Solved

Loop back 14 months using SQL query

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

740 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