Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Datepart Where Clause not working

I am having a problem with the end of a complicated 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 in it returns nothing. ESCDATE is a DATETIME field. I thought at first it wasn't passing integers to it but strings, and it is definitely passing integers.

Further up in the ASP script I am using Request.Querystring to get a month and a year and I basically want to check against ESC date that it only brings results back from the month specified in the year specified.

like image 615
Trinitrotoluene Avatar asked Nov 21 '25 07:11

Trinitrotoluene


1 Answers

The 'y' specifier is day of year, not year. Try 'yy' or 'yyyy' instead.

like image 63
verdesmarald Avatar answered Nov 23 '25 22:11

verdesmarald



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!