clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2555496 fiddles created (37440 in the last week).

CREATE TABLE dbo.splunge ( [date] DATE, Frequency INT ); INSERT dbo.splunge([date], Frequency) VALUES ('2014-05-18',5), ('2014-05-20',7), ('2014-05-25',7), ('2014-05-27',6); CREATE TABLE dbo.Calendar(d DATE PRIMARY KEY); INSERT dbo.Calendar(d) SELECT TOP (365) DATEADD(DAY, ROW_NUMBER() OVER (ORDER BY number)-1, '20140101') FROM [master].dbo.spt_values WHERE [type] = N'P' ORDER BY number; DECLARE @s DATE = '20140518', @e DATE = '20140527'; SELECT c.d, Frequency = COALESCE(s.Frequency,0) FROM dbo.Calendar AS c LEFT OUTER JOIN dbo.splunge AS s ON c.d = s.[date] WHERE c.d >= @s AND c.d < DATEADD(DAY, 1, @e);
d Frequency
2014-05-18 5
2014-05-19 0
2014-05-20 7
2014-05-21 0
2014-05-22 0
2014-05-23 0
2014-05-24 0
2014-05-25 7
2014-05-26 0
2014-05-27 6
 hidden batch(es)