Handling NULL in Sql server string concatenation
问题 I have the following SQL query select s.comments + s.further_comments from dbo.samples s where id = 1234 However if s.comments or s.further_comments is NULL the whole string is returned NULL How do I convert the NULL value to an empty string or at least only return the non NULL values in this string? 回答1: You can use either ISNULL or COALESCE for this. SELECT ISNULL(s.comments, '') + ISNULL(s.further_comments, '') SELECT COALESCE(s.comments, '') + COALESCE(s.further_comments, '') ISNULL