![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am running into an issue when adding data from multiple columns into one alias: P.ADDR1 + ' - ' + P.CITY + ',' + ' ' + P.STATE AS LOCATION If one of the 3 values is blank, the value LOCATION becomes NULL. How can I inlcude any of the 3 values without LOCATION becoming NULL? Example, if ADDR1 and CITY have values but STATE is blank, I get a NULL statement for LOCATION. I still want it to show ADDR1 and CITY even if STATE is blank. Thanks |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
You can use COALESCE, something like this will do it: COALESCE(P.ADDR1, '') + ' - ' + COALESCE(P.CITY, '') + ', ' + COALESCE(P.STATE, '') AS LOCATION Also, you can play with formatting variations based on what you want to get when one of the columns is NULL, like this: COALESCE(P.ADDR1, '') + COALESCE(' - ' + P.CITY, '') + COALESCE(', ' + P.STATE, '') AS LOCATION HTH, Plamen Ratchevhttp://www.SQLStudio.com |
#5
| |||
| |||
|
|
Somebody at work told me to use this: SELECT CASE WHEN P.STATE IS NULL THEN '' ELSE P.STATE END It seems to work. Is this similar as to what is described above? |
![]() |
| Thread Tools | |
| Display Modes | |
| |