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
 General SQL Server Forums
 New to SQL Server Programming
 Append data into a null field

Author  Topic 

sqlobsessed
Starting Member

8 Posts

Posted - 2012-06-03 : 00:19:00
I figured out this statement below to append 'test' into a field that already contains data that I do not want to override. Problem:If the field does not data and is NULL, this statement does not add 'test' into the field. How should I modify my update statement?

update orderdetail

set comments= comments +' '+ 'test'

where orderid=1028

mani_12345
Starting Member

35 Posts

Posted - 2012-06-03 : 00:25:17
yes off course u get null becz anything concatenatd with null alwys give u a null
for this u can use replace(<column name >,'null','value u want to enter ' )
i thnk u vl get appropriate answer ..
Go to Top of Page

sqlobsessed
Starting Member

8 Posts

Posted - 2012-06-03 : 00:37:00
Thanks, that makes sense. I am making a general statement that appends all fields, NULL or not.

Where exactly do I place your suggestion where it will run properly?:

update orderdetail
set comments= comments +' '+ 'test'
replace(<comments>,'null','test ' )
where orderid=1028
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-03 : 00:43:44
[code]
update orderdetail

set comments= coalesce(comments +' ','')+ 'test'

where orderid=1028ode
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sqlobsessed
Starting Member

8 Posts

Posted - 2012-06-03 : 00:48:59
Thank you both so much! It works for both :o) Alot of people are going to be very happy with this in my company!
Go to Top of Page

mani_12345
Starting Member

35 Posts

Posted - 2012-06-03 : 00:59:42
nice :)
Go to Top of Page
   

- Advertisement -