Solved

sql server 2008 query

Posted on 2013-11-26
2
447 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:
Scott Pletcher 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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 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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

778 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