Select column, if blank select from another Select column, if blank select from another sql sql

Select column, if blank select from another


How about combining COALESCE and NULLIF.

SELECT COALESCE(NULLIF(SomeColumn,''), ReplacementColumn)FROM SomeTable


You can use a CASE statement for this

select Case WHEN Column1 = '' OR Column1 IS NULL OR LEN (TRIM (Column1))  = 0      THEN Column2      ELSE Column1 END as ColumnNamefrom TableName


EDIT: You can't use IF() in mssql.

Use an IF statement in the SELECT portion of your SQL:

SELECT IF(field1 != '', field1, field2) AS myfield FROM ...