我有以下内容:
Select Coalesce(Other,Industry) Ind from registration
问题是它Other可以是一个空字符串或NULL. 我如何开始coalesce工作,如果Other是一个空字符串,Coalesce仍然返回Industry?
我有以下内容:
Select Coalesce(Other,Industry) Ind from registration
问题是它Other可以是一个空字符串或NULL. 我如何开始coalesce工作,如果Other是一个空字符串,Coalesce仍然返回Industry?
使用CASE表达式或NULLIF:
SELECT COALESCE(NULLIF(Other,''),Industry) Ind FROM registration
试试这个
Select Coalesce(nullif(Other,''),Industry) Ind from registration
NULL <> ''您也可以使用不会评估为TRUE...的捷径知道
CASE WHEN other <> '' THEN other ELSE industry END
然后逻辑如下...
CASE WHEN 'fubar' <> '' THEN other ELSE industry END
=> CASE WHEN true THEN other ELSE industry END
=>other
CASE WHEN '' <> '' THEN other ELSE industry END
=> CASE WHEN false THEN other ELSE industry END
=>industry
CASE WHEN NULL <> '' THEN other ELSE industry END
=> CASE WHEN NULL THEN other ELSE industry END
=>industry