I want to show all dates between two dates when there is any date data missing then its should show zero in val column .
declare @temp table (
id int ident
This will work as long as there are less than 2047 days between from and to dates
declare @from smalldatetime = '10/01/2012'
declare @to smalldatetime = '10/15/2012'
select t.id, dateadd(day, number,@from), isnull(val, 0) val from @temp t
right join master..spt_values s
on dateadd(d, s.number, @from) = t.CDate
where
datediff(day, @from, @to ) > s.number
and s.type = 'P'