Friday, February 10, 2012

Concatenating null fields in an SQL server query

I am concatenating 2 fields in a query. When one of the fields is a null
value the resulting string is also null wether the other string is null or
not. I have tried setting the concat_null_yields_null to off and on without
any change to the resulting string. Does anyone have any ideas about what I
might try next?
Thanks!
On Wed, 9 Mar 2005 14:23:01 -0800, Bob Boles wrote:

>I am concatenating 2 fields in a query. When one of the fields is a null
>value the resulting string is also null wether the other string is null or
>not. I have tried setting the concat_null_yields_null to off and on without
>any change to the resulting string. Does anyone have any ideas about what I
>might try next?
>Thanks!
Hi Bob,
Use
SELECT COALESCE(Column1, '') + COALESCE(Column2, '')
FROM YourTable
WHERE ...
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

No comments:

Post a Comment