J W is close, I think, but the actual formula you want, I believe, is:
S.Address1 + COALESCE(' , ' + NULLIF(S.Address2,''),'') as Address1
(Below not relevant, since OP has now said the column value is blank, not NULL
)
But you also have another issue - the above won't work (yet) because you apparently have CONCAT_NULL_YIELDS_NULL
set to OFF
. This need to be turned on (usually by setting ANSI_NULLS
to ON
), since:
In a future version of SQL Server CONCAT_NULL_YIELDS_NULL
will always be ON
and any applications that explicitly set the option to OFF will generate an error. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.