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
 Old Forums
 CLOSED - General SQL Server
 REPLACE

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-08-01 : 08:55:45
tim writes "Okay how to you replace a NULL value.

replace(phone, "/", "-")

works

but

replace(phone, NULL, "None");

doesn't."

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-08-01 : 08:58:45
You're a little off on the concept of Null. Null is not a value, and it is not part of a string. You can't "replace" a null in a string; either the entire column is Null or it isn't Null. You'd have to use something like IsNull to do what you want:

SELECT IsNull(phone, 'None')
FROM myTable


If the phone column is null, the IsNull function will subsitute the 'None' value. You can also combine it with your earlier code:

SELECT IsNull(Replace(phone, '/', '-'), 'None')
FROM myTable


Go to Top of Page
   

- Advertisement -