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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to det last3 months

Author  Topic 

krish001
Yak Posting Veteran

61 Posts

Posted - 2010-03-05 : 04:08:37

I need to get last 3 months as FEB2010 JAN2010 DEC2009

which query will help me

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-05 : 04:15:00

select left(datename(month,dates),3)+datename(year,dates) as dates from
(
select dateadd(month,-number,getdate()) as dates from master..spt_values
where type='p' and number between 1 and 3
) as t

Why do you need this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-05 : 09:52:43
seems like for dynamic pivot. then you could do this after getting date values

http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -