检查字段中的多个空值

时间:2017-08-29 20:12:52

标签: sql sql-server

尝试检查多个字段的空值,以便创建没有空值的主字段。在下面的情况下,我试图检查几个“城市”字段,直到我得到一个非空值,但这个语句没有按预期工作。

CASE
WHEN b.BillingCity IS NULL THEN b.ShippingCity
WHEN b.BillingCity IS NULL AND b.ShippingCity IS NULL THEN c.BillingCity
WHEN b.BillingCity IS NULL AND b.ShippingCity IS NULL AND c.BillingCity IS NULL THEN b.ES_APP__ESCity__c
WHEN b.BillingCity IS NULL AND b.ShippingCity IS NULL AND c.BillingCity IS NULL AND b.ES_APP__ESCity__c IS NULL THEN b.Avn_City__c
ELSE Null
END
As MasterCity

1 个答案:

答案 0 :(得分:6)

您可以使用COALESCE

SELECT COALESCE(b.BillingCity,b.ShippingCity,c.BillingCity,.....)