This is my code.
declare @dt datetime;
declare @AddTime int;
declare @earliestTime int;
declare @latestTime int;
declare @basedTime int;
set @dt = cast('01-01-1980 00:00:00' as datetime)
select @earliestTime = min(DATEDIFF(MINUTE, @dt, starttime)) from visit
select @latestTime = max(DATEDIFF(MINUTE, @dt, starttime)) from visit
set @AddTime = 30;
set @basedTime = @earliestTime;
set @earliestTime = @earliestTime + @AddTime;
SELECT
count(DATEDIFF(MINUTE, @dt, starttime)) as 'Ticket Issued',
@earliestTime as 'Period',
count(DATEDIFF(MINUTE, @dt, nexttime)) as 'Called Tickets',
SUM(case when DATEDIFF(second, starttime, nexttime) <= 900 then 1 else 0 end)
as 'Less than Accepted Waiting Time'
from visit
where DATEDIFF(MINUTE, @dt, starttime)between @basedTime and @earliestTime
What I want is.. I want to do the query again and again till @earliestTime > @latestTime
I know I am supposed to use stored procedure.. But I am not sure how to use that..
try this
hope this helps