Hello,
The following SQL function works fine when there is no dayofweek clause.
I need to be able to do calculations on certain days of the week and when I add the dayofweek clause, my query no longer works.
try (Transaction tx1 = persistence.createTransaction()) {
TypedQuery<ACD> queryATraiter = persistence.getEntityManager().createQuery("select c.debutplage, " +
"avg(c.appelsRecusOuverts) " +
"from avancial$ACD c " +
"where ((c.date between :dDebut and :dFin) AND (c.debutplage between :hdebut and :hfin) " +
"AND (c.debutplage < :hfin)) " +
"AND (dayofweek(c.date) = :dDay) " +
"group by c.debutplage, c.finplage", ACD.class);
queryATraiter.setParameter("dDebut", dateDebut);
queryATraiter.setParameter("dFin", dateFin);
queryATraiter.setParameter("hdebut", heureDebutPlage);
queryATraiter.setParameter("hfin", heureFinPlage);
queryATraiter.setParameter("dDay", 1);
List<ACD> aCD = queryATraiter.getResultList();
tx1.commit();
Error message :
JpqlSyntaxException: Errors found for input jpql:[select c.debutplage, avg(c.appelsRecusOuverts) from avancial$ACD c where ((c.date between :dDebut and :dFin) AND (c.debutplage between :hdebut and :hfin) AND (c.debutplage < :hfin)) AND (dayofweek(c.date) = :dDay) group by c.debutplage, c.finplage]
CommonErrorNode [<unexpected: [@70,196:196=’(’,<23>,1:196], resync=dayofweek(c.date>]
Thank you for your help,
regards,
Stephane