if i use this query thath creates a table(look Table1), But VisitingGap column is not correct format. i used cast method to give format. But not working correctly.i need
Table2
declare @date1 nvarchar(100) , @date2 nvarchar(100) , @countgap int,@count int
set @date1='2009-05-12'
set @date2 = '2009-05-13'
set @countgap = 30
set @count=48
CREATE TABLE #Temp (VisitingCount int, [Time] int, [Date] datetime )
DECLARE @DateNow DATETIME,@i int,@Time int, @Date datetime
set @DateNow='00:00'
set @i=1;
while(@i<@count)
begin
set @DateNow = DATEADD(minute, @countgap, @DateNow)
set @Time = (datepart(hour,@DateNow)*60+datepart(minute,@DateNow))/@countgap
set @Date = CONVERT(VARCHAR(5),@DateNow, 108)
insert into #Temp(VisitingCount,[Time],[Date]) values(0,@Time,@Date )
set @i=@i+1
end
select
Sum(VisitingCount) as VisitingCount, [Time],
Cast([Time]*@countgap/60 as nvarchar(50)) +':'+Cast( [Time]*@countgap%60 as nvarchar(50))
from (
select 0 as VisitingCount, [Time] from #Temp
Union All
select count(page) as VisitingCount,
(datepart(hour,Date)*60+datepart(minute,Date))/@countgap as [Time]
from scr_SecuristLog
where Date between @date1 and @date2
GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap
) X
group by [Time]
order by 2 asc
Table 1 :
.
.
.
VCount Time VisitingGap
0 1 0:30
0 2 1:0
0 3 1:30
0 4 2:0
0 5 2:30
0 6 3:0
0 7 3:30
0 8 4:0
0 9 4:30
0 10 5:0
.
.
.
Table 2 : i need below table !!!!
.
.
.
VCount Time VisitingGap
0 1 00:30
0 2 01:00
0 3 01:30
0 4 02:00
0 5 02:30
0 6 03:00
0 7 03:30
0 8 04:00
0 9 04:30
0 10 05:00
.
.
.
Look please! i think problem the cast method
Cast([Time]*@countgap/60 as nvarchar(50)) +':'+Cast( [Time]*@countgap%60 as nvarchar.........