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
 remove empty strings from results

Author  Topic 

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-02-06 : 15:39:27
i am makin an address block

trying to make it (address1 + ' ' + address2 + ' ' + address3) as address

is there a way to get rid of the address2 if there is nothing in it

Kristen
Test

22859 Posts

Posted - 2007-02-06 : 15:49:31
"is there a way to get rid of the address2 if there is nothing in it"

Does "nothing in it" mean it is NULL, or an Empty String?

(address1 + ' ' + COALESCE(address2 + ' ', '') + address3

would do for the NULL scenario, and

(address1 + ' ' + COALESCE(NullIf(address2, '') + ' ', '') + address3

for the "empty string" scenario

Kristen
Go to Top of Page

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-02-06 : 16:10:35
it could be either null or empty dependent upon whether it was entered then erased
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-02-06 : 16:40:56
Please work-up a solution based my second example then

Kristen
Go to Top of Page
   

- Advertisement -