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,767 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
ID: 12072909
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

930 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