shanmugavel
shanmugavel

Reputation: 199

How to count each date value in between statement?

SELECT COUNT(VALUE) 
FROM TABLE 
WHERE ID ='ID' 
AND BETWEEN 'DATE1' AND 'DATE2'

But I need the count for each date how to do that...eg date is 1/1/2012 to 4/1/2012....I need count for each date like 1,2,3,4.

Upvotes: 2

Views: 180

Answers (1)

Lieven Keersmaekers
Lieven Keersmaekers

Reputation: 58441

You add a GROUP BY clause

SELECT CONVERT(VARCHAR(10), YourDate, 101), COUNT(VALUE) 
FROM TABLE 
WHERE ID ='ID' 
AND Yourdate BETWEEN 'DATE1' AND 'DATE2'
GROUP BY CONVERT(VARCHAR(10), YourDate, 101)

The catch using dates is to get rid of the time part. Using CONVERT with style 101 does just that.

Upvotes: 1

Related Questions