concatenate two database columns into one resultset column

后端 未结 7 2167
独厮守ぢ
独厮守ぢ 2020-11-28 10:00

I use the following SQL to concatenate several database columns from one table into one column in the result set:

SELECT (field1 + \'\' + field2 + \'\' + field

7条回答
  •  离开以前
    2020-11-28 10:12

    Normal behaviour with NULL is that any operation including a NULL yields a NULL...

    - 9 * NULL  = NULL  
    - NULL + '' = NULL  
    - etc  
    

    To overcome this use ISNULL or COALESCE to replace any instances of NULL with something else..

    SELECT (ISNULL(field1,'') + '' + ISNULL(field2,'') + '' + ISNULL(field3,'')) FROM table1
    

提交回复
热议问题