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
 Adding text if value is empty

Author  Topic 

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-03-09 : 12:45:08
I'm performing an insert, and I want to insert specified text, if the field is empty. I thought it should be a simple matter of a case expression, which I have below, but it's not working:

CASE PropertyBuilding when '' then [PropertyStreetAddress] else [PropertyBuilding]end

Kristen
Test

22859 Posts

Posted - 2006-03-09 : 12:58:20
Maybe PropertyBuilding is NULL and will fail the "equals" test?

You could do

COALESCE( NullIf(PropertyBuilding, ''), PropertyStreetAddress)

this will give you PropertyBuilding if its not NULL AND not empty string, otherwise you will get PropertyStreetAddress

Kristen
Go to Top of Page
   

- Advertisement -