SQL using If Not Null on a Concatenation

后端 未结 8 1698
孤独总比滥情好
孤独总比滥情好 2021-01-01 15:22

If I have the table

SELECT (Firstname || \'-\' || Middlename || \'-\' || Surname)  AS example_column
FROM example_table

This will

8条回答
  •  -上瘾入骨i
    2021-01-01 15:39

    • The NULLIF expression reduces blank Middlename to NULL
    • Concatenating '-' with a NULL will always return NULL
    • TheVALUE expression replaces NULLs with an empty string

    _

    SELECT Firstname || VALUE( '-' || NULLIF('Middlename',''),'') || '-' || Surname'  
           AS example_column
    FROM example_table
    

提交回复
热议问题