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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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