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 2000 Forums
 Transact-SQL (2000)
 Adding with NULL values

Author  Topic 

ninel
Posting Yak Master

141 Posts

Posted - 2005-07-07 : 11:57:49
I have 3 columns that need to be summed up, but any one of these can contain a NULL value.

Col1 Col2 Col3 Col4
A 2.67 4.7 2.8
B 6.2 NULL 2.6
C 12.4 NULL NULL

How can I sum them up to look like this without updating the NULLS with a 0?

A = 10.17
B = 8.8
C = 12.4

Thanks,
Ninel

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-07-07 : 12:11:08
Lookup COALESCE in books on-line.

- Jeff
Go to Top of Page

CokoBWare
Starting Member

6 Posts

Posted - 2005-07-08 : 09:57:14
Try wrapping the Col2, Col3, and Col4 in ISNULL...

so, A = ISNULL(Col2,0) + ISNULL(Col3,0) + ISNULL(Col4,0)

ISNULL is really handy when you need to check for NULL and substitute without actually changing your table.

Go to Top of Page
   

- Advertisement -