Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Sum Query

Author  Topic 

phate06
Starting Member

17 Posts

Posted - 2014-02-10 : 04:43:41
hello
I need to show customer sales, where in 2012 there was sales but in 2013 there was not.
The table I have to get this from contains the columns CalenderYear, CalenderMonth and TotalSales.

The issue i have is summing the total sales by year and month for 2012 and then having the same for 2013 where it is showing 0.00.

I can join in the customer so that is ok, but it is the sales figures i am stuck on.

Any Ideas?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-02-10 : 10:45:20
You need to have a table - like a calendar table - that has one row for each reporting period. use that table first in your FROM clause and left outer join to the table with customer sales. Then in the SELECT list use COALESCE((SUM(Sales), 0) to make your NULLs show 0.00.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -