我需要通过在ISkeyProduct
和Country
上加入表格T1和T2来填充列Itemcode
(请参阅表的附件)。列iskeyproduct
中的最终值应为True或False,但不应为NULL。
我的代码是:
Update T1
Set IsKeyProduct = Case
When t2.ItemCode is not Null Then 1 Else 0
End
From T1
Left join T2 on t1.ShopCountry = t2.Country
and t1.ItemCode = case when t2.ItemCode
Where
(t1.ItemCode is not Null and t2.ItemCode is not null )
答案 0 :(得分:0)
你必须摆脱第二个谓词并修复JOIN ON
条件:
UPDATE T1
SET IsKeyProduct = CASE WHEN t2.ItemCode IS NOT NULL THEN 1 ELSE 0 END
FROM T1
LEFT JOIN T2
ON t1.ShopCountry = t2.Country AND t1.ItemCode = t2.ItemCode
WHERE t1.ItemCode IS NOT NULL
这个谓词:
t2.ItemCode is not null
过滤掉IsKeyProduct
应设置为0
的记录。