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 2000 Forums
 Transact-SQL (2000)
 How to get the last 13 month/year

Author  Topic 

ofsouto
Starting Member

22 Posts

Posted - 2005-01-15 : 13:55:19
Hi, dear

A date (GetDate()) is a stored procedure inside parameter.
I need to list the last 13 month/year.
I need to generate a query where I can get the result bellow:

01/2005
12/2004
11/2004
...
02/2004
01/2004

Is it possible? How can I get it without creating a table?

Thank you very much

Obede
Brazil

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-15 : 14:39:57
declare @dte datetime
select @dte = getdate()

select convert(varchar(6),dateadd(mm,i*-1,@dte),112)
from
(select i = i1.i + i2.i + i3.i + i4.i
from
(select i = 0 union select 1) as i1 ,
(select i = 0 union select 2) as i2 ,
(select i = 0 union select 4) as i3 ,
(select i = 0 union select 8) as i4
) as ints
where i <= 13
order by i


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -