String Concatenation in SQL Server
When using '+' to concatenate two string field in SQL server (e.g. a+b), if one of them is NULL, then the whole string will become NULL. There is one solution to solve it:
So if any of the field is NULL, it will evaluate as an empty string. That's it!
COALESCE(a,'') + COALESCE(b,'')
So if any of the field is NULL, it will evaluate as an empty string. That's it!
You could also use the more intuitive:
ReplyDeleteISNULL(a, '') + ISNULL(b, '')
My Blog: http://theplague.wordpress.com/
Sir, you are a genius, and saved me from panicking all over the coming weekend.
ReplyDeleteThank you!!