COALESCE
changes only NULL
values, not empty strings.
To be able to use another comparison, use CASE
:
SELECT CASE WHEN SenderName <> '' THEN SenderName ELSE 'empty' END FROM TableRec
(The expression SenderName <> ''
fails for both empty strings and NULL
s.)
To combine three fields, you must nest multiple CASE
expressions:
SELECT CASE WHEN SenderName <> ''
THEN SenderName
ELSE CASE WHEN SenderEmailId <> ''
THEN SenderEmailId
ELSE SenderMobileNumber
END
END
FROM TableRec