Solved

SQL SUM Function. Sum the column value to get Grand Total. If one of the column having null value then it does not return the SUM value i.e. The GrandTotal.

Posted on 2004-09-16
1
1,762 Views
Last Modified: 2008-03-17
Hi,

           I would like to sum up three column value.

ProjectID      GETotal          GMTotal         GOTotal             GrandTotal
10                  1000              <null>             2000                                           ' I don't get sum value here because of null
12                   8000           1000                  500                     9500                

SELECT     SUM(GETotal + GMTotal + GOTotal) AS GrandTotal, ProjectID, GETotal, GOTotal, GMTotal
FROM         dbo.View_EMTOBudget
GROUP BY ProjectID, GETotal, GOTotal, GMTotal

But i have to get 3000 for the ProjectID 10.

How do i do it if some of the column has null value.

Thank you.
0
Comment
Question by:casstd
1 Comment
 
LVL 17

Accepted Solution

by:
BillAn1 earned 150 total points
Comment Utility
use ISNULL - it replaces the value with a value (in this case 0) if it is NULL :

SELECT     SUM( isnull(GETotal,0) + isnull(GMTotal,0) + isnull(GOTotal,0)) AS GrandTotal, ProjectID, GETotal, GOTotal, GMTotal
FROM         dbo.View_EMTOBudget
GROUP BY ProjectID, GETotal, GOTotal, GMTotal
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

763 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

6 Experts available now in Live!

Get 1:1 Help Now