Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a query to return record set for each day of mo
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00719788
Message ID:
00719912
Views:
23
Michael

Thanks for the sample, here is what I finally came up with as the stored procedure:
CREATE PROCEDURE ctGetDayCount
@ltQueryFrom datetime,
@ltQueryTo Datetime

 AS


create table #output(
    thisDay datetime,
    total int,
   SchMin int,
   ORMin int
)

while @ltQueryFrom <= @ltQueryTo
begin
    insert into #output
    SELECT @ltQueryFrom, count(*), 
    isnull(sum(datediff(mi,begintime,endtime)),0) as SchedMinutes,
    isnull(sum(datediff(mi,enteror, exitor)),0) as ORMinutes
    FROM meetings 
    WHERE begintime BETWEEN @ltQueryFrom AND @ltQueryFrom + 1
    and meetings.iscompleted=1
    and meetings.iscancelled=0
    select @ltQueryFrom = @ltQueryFrom + 1
end

select * from #output
drop table #output
GO
This gives me all the dates between the date range passed.

Kirk
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform