Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating a query to return record set for each day of month
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Creating a query to return record set for each day of month
Divers
Thread ID:
00719788
Message ID:
00719788
Vues:
58
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform