sql server - MSSQL get a table with (months + year) between two dates -
i have table month + year between 2 dates using mssql server. lets given dates 01/02/2012 05/04/2012. table should this
feb 2012 mar 2012 april 2012
any suggestions achieving highly appreciated?
try 1 -
query:
declare @start date = '20120201' , @end date = '20120405' ;with cte ( select dt = dateadd(day, -(day(@start) - 1), @start) union select dateadd(month, 1, dt) cte dt < dateadd(day, -(day(@end) - 1), @end) ) select convert(char(4), dt, 100) + convert(char(4), dt, 120) cte
output:
-------- feb 2012 mar 2012 apr 2012
Comments
Post a Comment