如何更新基于一个列的值
问题描述:
我使用SQL服务器的不同列2008年。我有2个表如何更新基于一个列的值
指示灯
Id | Region
Indicator12
Id | Name | South America |North America
现在我需要更新南美洲(SA),北美(NA)列,如果某个特定ID在Indicator
表映射到两个区域,然后SA和NA列都应标记为YES
否则如果它只映射到一个区域,则Indicator12
中的各列应标记为YES
。
答
我想这是你所追求的 -
update Indicator12
set [South America] = case when Indicator.Region = 'SA'
then 'YES'
else Indicator12.[South America]
end,
[North America] = case when Indicator.Region = 'NA'
then 'YES'
else Indicator12.[North America]
end
from Indicator12
join Indicator
on (Indicator12.Id = Indicator.Id)