Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
How do i write calculation for 12 month period starting which is February of every year to January of next year. i have time table which has three years of data by year, quarter, month..How can i achieve this in a calculated column..12 month period2008 feb, march, apr, may, jun, jul, aug, sep, oct, nov,dec, 2009 jan.ThanksSid
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2011-01-16 : 06:17:53
may be this?
SELECT YEAR(date),DATENAME(mm,date)FROM tableWHERE datefield >= DATEADD(mm,1,DATEADD(yy,@year-1900,0))AND datefield < DATEADD(mm,1,DATEADD(yy,@year-1899,0))GROUP BY YEAR(date),MONTH(date),DATENAME(mm,date)ORDER BY YEAR(date),MONTH(date)
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/