sql server 2008 r2 - Only display a character if the ISNULL has a valid entry -
in sql server, i'm looking @ doing concatenating 2 fields together. so, example, have layout:
col1 col2 building room 101 building b room 2a building c room 301 building d building e room 200 and want concatenate them like:
building a-room 101 building b-room 2a building c-room 301 what happening when comes building d get:
building d-
which awful. thought isnull([col1] + '-', '') display - character. there way add - value if [col2] has value without using case statement? or going in wrong approach?
i think test needs evaluate col2, not col1. try this
select [col1] + isnull('-' + [col2], '')
Comments
Post a Comment