Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a query to return record set for each day of month
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Creating a query to return record set for each day of month
Miscellaneous
Thread ID:
00719788
Message ID:
00719788
Views:
57
I need to create a stored procedure that when passed the starting date and ending date, will return a result set that has one record for day of the month and a count for how many records where scheduled for that day, even if there are no records for that day.

I can create a set now, grouped by date, but it will only return records for days where there are records. Days that don't have records are not return. On those days I need to return zero.
declare @ltQueryFrom datetime
declare @ltQueryTo   dateTime
declare @lnDays int

set @ltQueryFrom = '10/01/2002 00:00:00'
set @ltQueryTo   = '10/31/2002 23:59:59'


set @lnDays = datediff(dd,@ltQueryFrom,@ltQueryTo)

select datepart(dd,meetings.begintime) as DayOfMonth,
       count(meetings.meetingnumber) as DayCount
from meetings
where begintime between @ltQueryFrom and @ltQueryTo
group by datepart(dd,meetings.begintime)
order by datepart(dd,meetings.begintime)
Thanks for any ideas

Kirk
Next
Reply
Map
View

Click here to load this message in the networking platform