Code
use bn
set dateformat dmy
declare @start datetime, @stop datetime
declare @temp table (object_id int, t varchar(64), count_all int, count_bbox int)
select @start='14.01.2012',@stop='15.01.2012'
insert into @temp
select c.ObjectID,c.t,isnull(c.col,0),isnull(c2.col,0) from
(select ObjectID,CONVERT (varchar(15),tele_time,120)+'0:00' as t,COUNT(*) as col from dbo.SYS_DEV_ArchiveData
where tele_time between @start and @stop
group by ObjectID, CONVERT (varchar(15),tele_time,120)+'0:00'
) as c
left join
(select ObjectID,CONVERT (varchar(15),tele_time,120)+'0:00' as t,COUNT(*) as col from dbo.SYS_DEV_ArchiveData
where tele_time between @start and @stop and flags&4=0
group by ObjectID, CONVERT (varchar(15),tele_time,120)+'0:00'
) as c2 on c2.ObjectID=c.ObjectID and c.t=c2.t
select * from @temp order by t
select t,isnull(sum(count_all),0) sum_count_all,isnull(sum(count_bbox),0) sum_count_bbox from @temp group by t order by t