Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Count daily entries

Author  Topic 

Desmag
Starting Member

18 Posts

Posted - 2006-09-25 : 11:54:28
I'm trying to run a small statistic from my forum. I would like to know how many entries there were daily, say during the last 30 days.

I'm sure there were some similar posts in the past, it's just I'm not to sure what keywords to look for...

Thanks in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-09-25 : 11:58:15
Something like this ? ? Without information on your table, i can only assume

select coun(*) as entries
from forum
where datecol >= dateadd(day, -30, getdate())





KH

Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-09-25 : 12:00:48
>>how many entries there were daily

Assuming your "date" column is a datetime or smalldatetime datatype, you want to group by just the date (excluding time). The most efficient way to do this is using a combination of dateadd and datediff functions:

group by dateadd(day, datediff(day, 0, [<datetimeColumn>]), 0)

Be One with the Optimizer
TG
Go to Top of Page

Desmag
Starting Member

18 Posts

Posted - 2006-09-25 : 12:15:30
Thanks guys!

BTW. Cool trick - dateadd(day, datediff(day, 0, [<datetimeColumn>]), 0) - do drop all the info on time!
Go to Top of Page
   

- Advertisement -