using a conditional update statement in sql

后端 未结 2 1205
清酒与你
清酒与你 2020-12-08 18:18

I would like to have an update statement like this

 SELECT * from Employee
 WHERE age = CASE 
 WHEN (age < 20) THEN age=15
 WHEN (age > 20) THEN age=          


        
相关标签:
2条回答
  • 2020-12-08 18:54

    I think what you want is:

    UPDATE EMPLOYEE
    SET age =
    CASE WHEN AGE < 20 THEN 15
    ELSE 20 END
    
    0 讨论(0)
  • 2020-12-08 19:07

    You can use a case statement in an update as follows...

    UPDATE Employee 
    SET Age = CASE WHEN (age < 20) THEN 15
                  ELSE 20 END
    
    0 讨论(0)
提交回复
热议问题