开发者

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜