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 |
thanksfor help
Posting Yak Master
106 Posts |
Posted - 2009-04-24 : 18:44:04
|
I need to get the first and last 3 months in rolling 12 months data. month field is in varchar(10) format.For given month : 2009 04Rolling 12 months will be 2008 052008 062008 072008 082008 092008 102008 112008 122009 012009 022009 032009 04I was successfull in generating 12 months and need help in getting first 3 and last 3 months.thanks |
|
dsindo
Starting Member
45 Posts |
Posted - 2009-04-24 : 19:32:36
|
create table #temp (mo varchar(10))insert into #temp values( '2008 05')insert into #temp values('2008 06')insert into #temp values('2008 07')insert into #temp values('2008 08')insert into #temp values('2008 09')insert into #temp values('2008 10')insert into #temp values('2008 11')insert into #temp values('2008 12')insert into #temp values('2009 01')insert into #temp values('2009 02')insert into #temp values('2009 03')insert into #temp values('2009 04')select top 3 mo as fisrt_3_months from #temp order by mo descselect top 3 mo as last_3_months from #temp order by mo asc |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-04-25 : 00:13:41
|
[code]select dateadd(month, n, '2009-04-01')from ( select n = 0 union all select n = -1 union all select n = -2 union all select n = -11 ) n[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
thanksfor help
Posting Yak Master
106 Posts |
Posted - 2009-04-27 : 12:15:36
|
thanks, it worked !!!! |
|
|
|
|
|