SQL datepart where clause doesn't work

I have a problem with the end of a complex query:

SQLString = "SELECT i.CONCOM, 
                    COALESCE(SUM(CASE 
                                   WHEN C.CATEGORY_ID = '30' THEN 0 
                                   ELSE t.LOGMINS END), 0) AS TotalWithoutNew, 
                    COALESCE(SUM(t.LOGMINS), 0) AS TotalAllId 
               FROM Inquiry AS i 
         INNER JOIN TIMELOG AS t ON t.INQUIRY_ID = i.INQUIRY_ID 
         INNER JOIN PROD AS P ON i.PROD_ID = P.PROD_ID 
         INNER JOIN CATEGORY AS C ON P.CATEGORY_ID = C.CATEGORY_ID 
              WHERE (DATEPART(m, ESCDATE) = " & objmonth & ") 
                AND (DATEPART(y, ESCDATE) = " & objyear & ") 
           GROUP BY i.CONCOM 
           ORDER BY concom ASC"

The query works fine without the where clause, but when I put the where clause, it returns nothing. ESCDATE- field DATETIME. I thought that at first he did not pass integers to him, but strings, and he definitely passes integers.

Further in the ASP script, I use Request.Querystringto get the month and year, and I basically want to check the ESC date that it returns results only from the month specified in the specified year.

+3
source share
1 answer

The qualifier "y" is the day of the year, not the year. Instead, try yy or yyyy.

+4
source

All Articles