I have a table with multiple address columns
Address1 | Address2 | Address3 | Address4 | City | County | PostCode
Address1 and PostCode will always be populated, the other columns may contain null. I want to have a computed column that can hold the full address, excluding null columns, but inserting char(10) and char(13) linefeeds after each column that is not null.
Coalesce and ISNULL don't allow me to add the linefeeds only after non null columns, and CASE WHEN ELSE END returns null if any one column contains null.
Can this be done?
You can use
CONCAT_WSfor this. The nulls are ignored, and each one is separated by the separator value (the first parameter).