我想用case语句做......但我的代码不工作......想要更正我在sql server express edition上写它,,,,, plz回复正确的SQL查询以及我的代码错误的原因......
我的代码是: -
update originals set LOYAL_TO = case when last_name = 'Mikelson'
then LOYAL_TO = 'KLAUS'
when first_name = 'KOL' then LOYAL_TO = 'NO ONE'
when first_name = 'DAVINA' then LOyal_to = 'MARCEL'
when first_name = 'camille' then loyal_to = 'MARCEL'
when first_name = 'vincent' then loyal_to = 'EVERYONE'
when first_name = 'josh' then loyal_to = 'MARCEL'
when FIRST_NAME = 'JACKSON' then loyal_to = 'HAYLEY'
when FIRST_NAME = 'Hollow' then loyal_to = 'DEMON'
end case from originals;
答案 0 :(得分:1)
你的语法到处都是。这样的东西就是你要找的东西。
update originals
set LOYAL_TO =
case last_name
when 'Mikelson' then 'KLAUS'
when 'KOL' then 'NO ONE'
when 'DAVINA' then 'MARCEL'
when 'camille' then 'MARCEL'
when 'vincent' then 'EVERYONE'
when 'josh' then 'MARCEL'
when 'JACKSON' then 'HAYLEY'
when 'Hollow' then 'DEMON'
end