Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Jul 20, 2000

Rolling 12-Month Totals

Question:
I have two similar tables with monthly data: one holds current year data and the other holds prior year data. How do I combine them to create a rolling 12-month view or table?

Answer:
If I understand your question correctly, you can use UNION to combine the results of two SELECT statements. Here's an example:

SELECT AccountID, Amount, Month, Year
FROM Table1
UNION
SELECT AccountID, Amount, Month, Year
FROM Table2
ORDER BY Year DESC, Month DESC
This will give you a resultset with the information from both years.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date