How can i join ( or union) #Temp with scr_SecuristLog Time. Look please [Time] column
CREATE TABLE #Temp (VisitingCount int, [Time] int )
DECLARE @DateNow DATETIME,@i int,@Time int
set @DateNow='00:00'
set @i=1;
while(@i<48)
begin
set @DateNow = DATEADD(minute, 30, @DateNow)
set @Time = (datepart(hour,@DateNow)*60+datepart(minute,@DateNow))/30
insert into #Temp(VisitingCount,[Time]) values(0,@Time )
set @i=@i+1
end
select Count(Page) as VisitingCount,[Time]
from
( SELECT Page,Date,[user],
(datepart(hour,Date)*60+datepart(minute,Date))/30 as [Time]
FROM scr_SecuristLog
) scr_SecuristLog
where
Date between '2009-05-04' and '2009-05-05'
group by [Time] order by [Time] asc
return