Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Query returning count for each day of month

Status
Not open for further replies.

KirkKelly

Programmer
Jan 5, 2001
15
US
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 down, group by date, but it will only return records for days where there are records. Days that don't have records are not return.

Thanks for any ideas

Kirk
 
create proc dayCount(
@sDate smalldatetime,
@eDate smallDatetime
)
as set nocount on
create table #output(
thisDay smalldatetime,
total int
)

while @sDate <= @eDate
begin
insert into #output
SELECT @sDate, count(*) FROM myTable
WHERE datetimecreate BETWEEN @sDate AND @sDate + 1
select @sDate = @sDate + 1
end

select * from #output
go
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top