Solved

Loop back 14 months using SQL query

Posted on 2006-11-30
5
770 Views
Last Modified: 2007-12-19
Hello All,

I need to loop through backwards 14 months (month wise) and get month and year. Lets say its November 2006 so 14 months back would be oct 2006, sep 2006, aug 2006.......dec 2005, nov 2005, oct 2005. I can use the datepart(month,getdate())-14 but the -ve value is not recognized. Is there a simpler way to loop back month wise from given date and then fetch the month and year.

Regards
RSRSM
0
Comment
Question by:rsrsm
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18044881
SELECT DATEADD(dd, -14, GETDATE())
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 300 total points
ID: 18044884
 Sorry


SELECT DATEADD(mm, -14, GETDATE())
0
 

Author Comment

by:rsrsm
ID: 18044958
Thats the fastest and the easiest ans...thankx aneeshattingal ...my mind is not at wrk today...thankx a lot..i was cracking this one frm morning :)
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18044972
Hi rsrsm,

Select DatePart(Month,DateAdd(month,-14,getDate())) ,DatePart(Year,DateAdd(month,-14,getDate()))

Tim Cottee
0
 

Author Comment

by:rsrsm
ID: 18045009
hey Tim, sorry I had already accepted aneeshattingal answer before you had posted....both answers are quick and serve my purpose....

I'm not sure if I can split the points now.

RSRSM
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now