This is your code snippets after changing
May be it will help you
DECLARE @tableinfo table (TAG_NAME varchar(50) not null,
DATE_TIME_COLLECTED datetime not null, F_CURRENT_TAG_VALUE real not null)
DECLARE @startDT datetime
DECLARE @endDT datetime
DECLARE @LB datetime
DECLARE @UB datetime
SET @startDT = '2012-07-24 01:00:00.720'
SET @endDT = '2012-07-24 11:15:51.810'
SET @LB = @startDT
SET @UB = DATEADD(HOUR,1,@LB)
if(@UB>@endDT) SET @UB = @endDT
while(@UB<=@endDT)
BEGIN
insert into @tableinfo
SELECT [TAG_NAME] ,MAX([DATE_TIME_COLLECTED]),MAX([F_CURRENT_TAG_VALUE]) FROM [FMCS].[dbo].[M_TAG_VALUE]
GROUP BY TAG_NAME
HAVING (DATE_TIME_COLLECTED BETWEEN @LB and @UB) AND TAG_NAME='XVI_5990'
SET @LB = @UB
SET @UB = DATEADD(HOUR,1,@LB)
END
select * from @tableinfo