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 2005 Forums
 .NET Inside SQL Server (2005)
 Nested row count, stored procedure or not

Author  Topic 

tgleason
Starting Member

1 Post

Posted - 2010-07-13 : 16:37:50
Hello,

I need row counts from a table for rows that match a date.
This Select below is for 1 date but I need the counts for each date in the table. Or a date range and/or dates that dont have rows corresponding to them. Dates that have no rows.

SELECT count(*) FROM table1 WHERE CONVERT(CHAR(10), timestamp1,101) = '07/13/2010'

I'm guessing this can't be done with a single select statement.
If so great, that would be best.

Any help is appreciated. Thank you.

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-13 : 16:51:53
your query is okey, if you want to get frequencies for each date.

either this:

select count(*)as frequency
,convert(char(10),timestamp1,101)
from table1
group by convert(char(10),timestamp1,101)
order by convert(char(10),timestamp1,101)


or if you want to have a date range do as following:


select count(*)as frequency
,convert(char(10),timestamp1,101)
from table1
where convert(char(10),timestamp1,101) between '07/10/2010' ane '07/14/2010'
group by convert(char(10),timestamp1,101)
order by convert(char(10),timestamp1,101)
Go to Top of Page
   

- Advertisement -