-5

i want to do it using case when statement......but my code isnt working......want correction i am writing it on sql server express edition,,,,,plz reply with correct sql query and reason for why my code is wrong...

MY CODE IS :-

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;
SQLChao
  • 7,709
  • 1
  • 17
  • 32
  • Read more about `CASE`, start from here - https://learn.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql?view=sql-server-2017 – Abhishek May 29 '18 at 15:05
  • Possible duplicate of [SQL Case Expression Syntax?](https://stackoverflow.com/questions/4622/sql-case-expression-syntax) – faintsignal May 29 '18 at 15:34

1 Answers1

1

Your syntax is all over the place. Something like this is what you are looking for.

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
Sean Lange
  • 33,028
  • 3
  • 25
  • 40