Solved

sql server 2008 query

Posted on 2013-11-26
2
441 Views
Last Modified: 2013-11-26
I'm using sql server 2008 R2.

I have a table that looks like this:

my table
How do I write a query to add the ItemAmounts by TransactionMonth.

So my desired result should look like this:

desired result set
I started the sqlfiddle for my example here.

http://sqlfiddle.com/#!3/fec2c/1
0
Comment
Question by:maqskywalker
2 Comments
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 400 total points
Comment Utility
SELECT BusinessYear, TransactionMonth, SUM(ItemAmount) AS ItemAmount
FROM tablename
GROUP BY BusinessYear, TransactionMonth
ORDER BY 1, 2
0
 
LVL 34

Assisted Solution

by:Brian Crowe
Brian Crowe earned 100 total points
Comment Utility
First, I'd like to thank you for posting the link to sqlfiddle.  I had no idea that was out there what a great tool for sites like this.  There are times I would like it mandatory for some of the questions I've attempted to answer here.

BTW, although ScottPletcher's answer above will work exactly as you requested; I would avoid using ordinal values in the ORDER BY clause.  Use the column names instead.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now