Easiest perhaps is to use a calendar table or numbers table. You can create one on the fly if you don't have a numbers table. For example:CREATE TABLE #tmpCalendarTable(dt DATETIME);DECLARE @startdate DATETIME, @days INT;SET @startdate = '20110701';SET @days = 30;WITH N(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM N WHERE n < @days)INSERT INTO #tmpCalendarTable SELECT DATEADD(dd,n-1,@startdate) FROM N;
Once you have the calendar table, you can do a left join:SELECT dtFROM #tmpCalendarTable t LEFT JOIN YourTable y ON y.Dt = t.dtWHERE y.dt IS NULL;