use a hour table to left join to your table.See below for illustrationdeclare @hour table ( hr int )declare @data table ( hr int, value int)insert into @data(hr, value)select 1, 10 union all select 2, 20 union allselect 4, 40 union all select 5, 50 union allselect 6, 60declare @i intselect @i = 0while (@i < 24)begin insert into @hour select @i select @i = @i + 1endselect * from @datahr value ----------- ----------- 1 102 204 405 506 60(5 row(s) affected)select h.hr, isnull(d.value, 0) as valfrom @hour h left join @data don h.hr = d.hrhr val----------- ----------- 0 01 102 203 04 405 506 607 08 09 010 011 012 013 014 015 016 017 018 019 020 021 022 023 0(24 row(s) affected)
KH