开发者

Concatenating strings containing NULL values

I want to concatenate a string

I want output like this:

NEX-SYM-VIM-CRE

If the input is NEX-NULL-开发者_JAVA技巧NULL-VRE, it comes out to be NEX---CRE or ---CRE or NEX--- as i have replaced NULL with -

But concatenation to get a final result like NEX-SYM is not coming


Something like this?

ISNULL(NEX,'-') + '-' + ISNULL(SYM,'-') + '-' + ISNULL(VIM,'-') + '-' + ISNULL(CRE,'-')


Always add a - delimiting character to the right but only when there is a value:

NULLIF(
       COALESCE(NEX + '-', '') 
          + COALESCE(SYM + '-', '') 
          + COALESCE(VIM + '-', '') 
          + COALESCE(CRE + '-', ''), ''
      )

then you always need to trim the last character (will be a - delimiting character) unless the result is NULL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜