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. 2555560 fiddles created (37480 in the last week).

CREATE TABLE dbo.splunge2 ( [date] DATE, Frequency INT ); INSERT dbo.splunge2([date], Frequency) VALUES ('2014-05-18',5), ('2014-05-20',7), ('2014-05-25',7), ('2014-05-27',6); DECLARE @s DATE = '20140518', @e DATE = '20140527'; SELECT c.d, Frequency = COALESCE(s.Frequency,0) FROM ( SELECT TOP (DATEDIFF(DAY, @s, @e)+1) DATEADD(DAY, ROW_NUMBER() OVER (ORDER BY number)-1, @s) FROM [master].dbo.spt_values WHERE [type] = N'P' ORDER BY number ) AS c(d) LEFT OUTER JOIN dbo.splunge2 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)