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)
 This is simple but ....

Author  Topic 

sahu74
Posting Yak Master

100 Posts

Posted - 2002-11-21 : 10:40:43
This might be simple but I just cannot get to do this...

I have a query in the format

SELECT a.total + b.total + c.total
FROM
(SELECT ....)a,
(SELECT ....)b,
(SELECT ....)c

The output of 'a' and 'c' are numbers but the output of 'b' is null. So the result I get is 'NULL' although 'a' and 'c' are numbers.

Can anyone help me with this please?

PKS

Lady
Starting Member

32 Posts

Posted - 2002-11-21 : 10:44:54
SET CONCAT_NULL_YIELDS_NULL


When SET CONCAT_NULL_YIELDS_NULL is ON, concatenating a null value with a string yields a NULL result. For example, SELECT 'abc' + NULL yields NULL. When SET CONCAT_NULL_YIELDS_NULL is OFF, concatenating a null value with a string yields the string itself (the null value is treated as an empty string). For example, SELECT 'abc' + NULL yields abc.

If not specified, the setting of the concat null yields null database option applies.



Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-11-21 : 10:52:22
or (as you are working with numbers)

SELECT coalesce(a.total,0) + coalesce(b.total,0) + coalesce(c.total,0)

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.

Edited by - nr on 11/21/2002 10:54:11
Go to Top of Page

Lady
Starting Member

32 Posts

Posted - 2002-11-22 : 04:40:32
isnull(a,'') + isnull(b,'')

Go to Top of Page
   

- Advertisement -