0

On a SELECT query i want to convert my DATETIME column to DATE format (taking only year, month and day).

I was using DATE construct: DATE(table.column) and it was great but it seems that this construct doesen't works on SQLSERVER databases (i was working on MySql previously).

This is the error i met:

 data type for node: org.hibernate.hql.ast.tree.MethodNode +-[METHOD_CALL] MethodNode: '(' | +-[METHOD_NAME] IdentNode: 'DATE'

Someone can help me fix this? I tried using CONVERT and CAST but i met same error.

This is the query:

SELECT DATE(al.loginTime) as loginTime, (COUNT(al.hawkUser)) as numeroAccessi, al.hawkUser as hawkUser, al.logoutTime as logoutTime " +
                "FROM AccessLog as al GROUP BY al.hawkUser, DATE(al.loginTime) ORDER BY DATE(al.loginTime) DESC, al.hawkUser DESC 
RemovedQuasar
  • 31
  • 1
  • 13

1 Answers1

0

Ok i modified several times the query, now is like this:

 String query="SELECT "
        + "  al.loginTime as loginTime,"
        + " (COUNT(hu.id)) as numeroAccessi, "
        + " hu.id as hawkUser "
                + "FROM AccessLog as al "
                + " INNER JOIN al.hawkUser hu "
                + " GROUP BY "
                + " al.loginTime,"
                + " hu.id "
                + " ORDER BY "
                + " al.loginTime DESC"
                + " hu.email  ";

loginTime is DATETIME with hours, minuted and seconds while i need to regroup them only using year month and day (it's a login list). So i still have to convert DATETIME to DATE. I can't use CAST and CONVERT since this query is for MySql and SQLServer database and the syntax is different for both.

RemovedQuasar
  • 31
  • 1
  • 13