Solved

Loop back 14 months using SQL query

Posted on 2006-11-30
5
811 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

749 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