I have a table with entries for each consecutive hour. Every hour has some meaning. I want the T-SQL query to retrieve the missing records (missing hours, spaces). So, for DDL below, I should get a record for the missing hour 04/01/2010 02:00 (assuming the date range is between the first and last record). Using SQL Server 2005. Prefer a set-based query.
DDL: CREATE TABLE [Readings]( [StartDate] [datetime] NOT NULL, [SomeValue] [int] NOT NULL ) INSERT INTO [Readings]([StartDate], [SomeValue]) SELECT '20100401 00:00:00.000', 2 UNION ALL SELECT '20100401 01:00:00.000', 3 UNION ALL SELECT '20100401 03:00:00.000', 45
sql sql-server tsql sql-server-2005 gaps-and-islands
Tony_henrich
source share