Solved

sql server 2008 query

Posted on 2013-11-26
2
443 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
ID: 39678620
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
ID: 39678699
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Detach & Attach 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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

910 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

21 Experts available now in Live!

Get 1:1 Help Now