sql - Months Between 2 dates for each Project -
hi trying run query return row each month between 2 dates each project have. see example data:
project start end 1 1/1/2015 3/1/2015 2 2/1/2015 4/1/2015
end data needed:
project month 1 1/1/2015 1 2/1/2015 1 3/1/2015 2 2/1/2015 2 3/1/2015 2 4/1/2015
i have several projects , need query of them @ same time. how can in sql server?
another option cross apply ad-hoc tally table
select a.project ,month = b.d yourtable cross apply ( select top (datediff(month,a.start,a.[end])+1) d=dateadd(month,-1+row_number() on (order by(select null)),a.start) master..spt_values ) b
returns
project month 1 2015-01-01 1 2015-02-01 1 2015-03-01 2 2015-02-01 2 2015-03-01 2 2015-04-01
Comments
Post a Comment