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
 SQL Server Development (2000)
 Addition or Sum of vars

Author  Topic 

skillile
Posting Yak Master

208 Posts

Posted - 2002-01-28 : 13:39:41
--I have a list of 20 numbers to add
--how can I add the vars and get a
--value some are null

declare @x int
declare @y int
declare @z int

set @x=null
set @y=1
set @z=1


select @x+@y+@z

--i want the answer to be 2

--Thanks


slow down to move faster...

chadmat
The Chadinator

1974 Posts

Posted - 2002-01-28 : 13:56:27
Use the IsNull function.

It converts NULL values to whatever you want them to be before adding them. So if they should be 0, then you would put:

Select isnull(@x, 0) + isnull(@y, 0) + isnull(@z, 0)

The answer would be 2

-Chad

Go to Top of Page
   

- Advertisement -