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
.
精彩评论