sql - Syntax for multiple cases in MySQL -


i have mysql update statement attempting reset 2 columns: label , perstrcode. (this in coldfusion program.) i'm doing case statements can't seem syntax right -- keep getting error. code:

<cfquery name = 'nonull' datasource = "moxart"> update finaggdb set label = case   when persactincoutg = 'i' && perstrcode null 'total income'  when persactincoutg = 'o' && perstrcode null 'total expense'  when persactincoutg null && perstrcode null ' '  else perstrcode end  set perstrcode = case   when perstrcode null 'total'  else perstrcode end  </cfquery> 

the error usual informative statement:

you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'set perstrcode = case when perstrcode null 'total' else perstrcode ' @ line 8

are multiple case statements not allowed? or can tell me how fix this?

an update statement has 1 set clause, various columns want update separated commas. also, note it's more common use and , not &&, although both valid in mysql:

update finaggdb set label = case   when persactincoutg = 'i' , perstrcode null 'total income'  when persactincoutg = 'o' , perstrcode null 'total expense'  when persactincoutg null , perstrcode null ' '  else perstrcode end ,  -- comma here, not second "set" clause perstrcode = case   when perstrcode null 'total'  else perstrcode end 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -