SQL using If Not Null on a Concatenation

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

If I have the table

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

This will

8条回答
  •  情深已故
    2021-01-01 15:44

    One solution could be using case statement

    select case Middlename is not null then (Firstname || '-' || Middlename || '-' || Surname) 
        else (Firstname || '-' || Surname) end AS example_column
    from ....
    

提交回复
热议问题