Solved

Loop back 14 months using SQL query

Posted on 2006-11-30
5
822 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

630 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