[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
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
Medium Priority
?
1,776 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
BillAn1 earned 600 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

656 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