T SQL Conditional String Concatenation

后端 未结 5 836
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 16:55

Have a 5 columns of address data. I need to concatenate these fields into a single address with spaces in between the values if they exist. If the column has a null value

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 17:30

    I have assumed your data types are all varchar or similar for simplicity. If you are OK with removing any double spaces, how about:

    rtrim(ltrim(replace(isnull(street_number) + ' ' 
        + isnull(street_ext) + ' ' 
        + isnull(street_direct) + ' ' 
        + isnull(site_street) + ' ' 
        + isnull(site_address), '  ', ' ')))
    

提交回复
热议问题