Wednesday, January 27, 2016

Three continuous month and year in SQL Server



Three continuous month and year in SQL eg

Nov 2015
Dec 2015
Jan 2016


Select  left(DateName( month , DateAdd( month , Month(@FCashReceivedDate) , -32 ) ),3)  +' '+ cast(Year(@FCashReceivedDate)  as varchar(4))
Select  left(DateName( month , DateAdd( month , Month(@FCashReceivedDate) , -1 ) ),3)  +' '+ cast(Year(@FCashReceivedDate)  as varchar(4))
Select  left(DateName( month , DateAdd( month , Month(@FCashReceivedDate) , 0 ) ),3)  +' '+   cast(year(DATEADD(year,1,@FCashReceivedDate) ) as varchar(4))

No comments: