Case expression is not working properly in sql query

后端 未结 4 1407
长情又很酷
长情又很酷 2021-01-29 15:20

I want to concat columns of supplier table with comma separator and put it into an alias field named \'contact\'. I have used cases for checking null values. Suppos

4条回答
  •  不知归路
    2021-01-29 15:53

    Use this

      SELECT supplier_Name, supplier_Address, supplier_reference, contact_Number1,
         contact_number2, contact_number3,
         case when contact_number2 is null then contact_number3 
              when contact_number3 is null then contact_number2 
              when contact_number3 is null and contact_number2 is null then '0'
              when contact_number2 is not null and contact_number3 is not null then contact_number2||','||contact_number3
         end as contact
      FROM SUPPLIER
    

提交回复
热议问题