I’ve been using this sytem function a lot lately, and it’s really useful!
I’m having to check for a phone number in several different places, and using Coalesce helped me avoid using a long drawn out Case Statement.
COALESCE(expression 1, expression 2, expression 3) [Phone Number]
The above code will be placed in your column select list. The Coalesce will check expression 1 (The first column you want to check) for a value, and if one is found, it will be returned, but if it’s NULL, then expression 2 will be checked, if that’s NULL, then expression 3 will be checked.
The function will check all of the expressions listed within the bracers until a value is found, so if expression 1 has a value, it will be returned and the function wont bother checking the others. If all of the expressions listed are NULL, then a NULL will be returned.
The “[Phone Number]” will just name the column “Phone Number” in the result set.
You may pass in as many expressions as necessary, but remember – the more expressions the function has to check, the worse your performance will be.