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 2005 Forums
 Transact-SQL (2005)
 Summing rows and nulls

Author  Topic 

magicman
Starting Member

6 Posts

Posted - 2008-01-11 : 11:07:53
Hi,

I am trying to sum 2 columns of a row to give the result in a third column. i.e SELECT ID, SpeedA + SpeedB AS Total From tblSpeeds.

The problem is that some of the SpeedB results are null, which results in the Total Column being a NULL. How can I substitute a NULL value in Column SpeedB with a value 0.00, so the statement works.

20.0 Null Null
25.0 5.0 30.0

Many thanks, Harry.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-11 : 11:08:59
SELECT ID, SpeedA + ISNULL(SpeedB,0) AS Total From tblSpeeds
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2008-01-11 : 11:32:37
or COALESCE(SpeedB, 0) if you are ANSIlly retentive
Go to Top of Page

magicman
Starting Member

6 Posts

Posted - 2008-01-14 : 02:21:23
Many thanks
Go to Top of Page
   

- Advertisement -