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.
Author |
Topic |
chennaraaj
Starting Member
17 Posts |
Posted - 2013-08-01 : 07:10:37
|
Hi,i need to display the last 30 days from given period.1234......30rk |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-08-01 : 07:34:40
|
[code]DECLARE @Period intSET @Period=201303;With PeriodDaysAS(SELECT DATEADD(yy,(@period/100)-1900,DATEADD(mm,(@Period%100)-1,0)) AS DateVal,1 AS NUNION ALLSELECT DATEADD(dd,1,DateVal),N+1FROM PeriodDaysWHERE 100 * YEAR(DATEADD(dd,1,DateVal)) + MONTH(DATEADD(dd,1,DateVal))< @Period+1)SELECT DateValFROM(SELECT dateVal,ROW_NUMBER() OVER (ORDER BY N DESC) AS SeqFROM PeriodDays)tWHERE Seq <=30ORDER BY DateVal OPTION (MAXRECURSION 0)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|
|
|