0

I can update my database vertically but how about horizontally in the same time ?

My code below here

UPDATE energy SET nov = CASE
WHEN label = 'myLabel' THEN '123'
WHEN label = 'myLabel2' THEN '123'
ELSE nov
END WHERE uname='123' AND years='2558'

2 Answers 2

0

Do you mean many fiels in a row:

    UPDATE   energy
   SET   nov =
            CASE
               WHEN label = 'myLabel' THEN '123'
               WHEN label = 'myLabel2' THEN '123'
               ELSE nov
            END
       , nov2 =
            CASE
               WHEN label2 = 'myLabel' THEN '3123'
               WHEN label2 = 'myLabel2' THEN '3123'
               ELSE nov2
            END
 WHERE   uname = '123' AND years = '2558'
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks anyway, it's work. Before that I use this SET nov,nov2 CASE WHEN label = 'myLabel' THEN ('123','123') WHEN label = 'myLabel2' THEN ('123','123') ELSE nov END WHERE uname = '123' AND years = '2558' Even this (nov=case......'2558,nov2=case...'2558') That's why I fail
0

You can also do like this..

UPDATE energy
 SET nov =
(select  CASE
WHEN label = 'myLabel' THEN '123'
WHEN label = 'myLabel2' THEN '123'
ELSE nov
END  as case)
WHERE uname='123' AND years='2558'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.