|
Posted by Plamen Ratchev on 02/08/07 19:51
You have to use COUNT for number of records, not SUM. You can use SUM to
summarize a value if needed. Here is an example:
CREATE TABLE #Test(mydate datetime, myvalue int)
INSERT INTO #Test VALUES(DATEADD(hour, 2, getdate()), 2)
INSERT INTO #Test VALUES(DATEADD(hour, 3, getdate()), 3)
INSERT INTO #Test VALUES(DATEADD(hour, 4, getdate()), 4)
SELECT COUNT(*) AS counts, SUM(myvalue) AS total
FROM #Test
WHERE mydate >= DATEDIFF(day, 0, getdate())
AND mydate < DATEDIFF(day, 0, getdate() + 1)
DROP TABLE #Test
Regards,
Plamen Ratchev
http://www.SQLStudio.com
Navigation:
[Reply to this message]
|