title: SQL Datepart Where Clause not working
body: <p>I am having a problem with the end of a complicated query:</p>
  
  <pre><code>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) = " &amp; objmonth &amp; ") 
                  AND (DATEPART(y, ESCDATE) = " &amp; objyear &amp; ") 
             GROUP BY i.CONCOM 
             ORDER BY concom ASC"
  </code></pre>
  
  <p>The query works fine without the where clause but when I put the where clause in it returns nothing. <code>ESCDATE</code> is a DATETIME field. I thought at first it wasn't passing integers to it but strings, and it is definitely passing integers.</p>
  
  <p>Further up in the ASP script I am using <code>Request.Querystring</code> 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. </p>