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)
 Adding NULLS

Author  Topic 

Luke101
Starting Member

30 Posts

Posted - 2009-06-18 : 09:13:57
Hello,
Every time I try to add a NULL with a string I always get a NULL. Is there a way i can change this behavior or is there a way to deal with this?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-18 : 09:36:09
Use COALESCE or ISNULL.


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Luke101
Starting Member

30 Posts

Posted - 2009-06-18 : 11:18:02
Would you happen to have any syntax examples?
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-06-18 : 11:45:29
SELECT field3 = coalesce(field1, '') + coalesce(field2,'')
from urtable

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-18 : 12:24:52
You mean other syntax than described in Books Online, the SQL Server help file?


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Luke101
Starting Member

30 Posts

Posted - 2009-06-18 : 21:40:18
I am doing something like this

update table set column1 = column1 + 'MyString' where column2 = 10

column 1 always returns a NULL
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-06-18 : 22:11:18
update table set column1 = COALESCE(column1,'') + 'MyString' where column2 = 10

ps.It works but i not sure it meet yours requirement, plz wait peso and others pro to double confirm it
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-06-19 : 00:10:25
quote:
Originally posted by Luke101

I am doing something like this

update table set column1 = column1 + 'MyString' where column2 = 10

column 1 always returns a NULL



The column1 has null value in the table, that's why u got the column1 value as null.
check the column1 with isnull or coalesce
Go to Top of Page
   

- Advertisement -