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= 20
Is this not possible in SQL Server / MySQL. I do not want to use the stored procedures or other things.
这在SQL Server / MySQL中是不可能的吗?我不想使用存储过程或其他东西。
Suggest me a suitable way around this problem
建议我一个合适的方法来解决这个问题
2 个解决方案
#1
68
I think what you want is:
我认为你想要的是:
UPDATE EMPLOYEE
SET age =
CASE WHEN AGE < 20 THEN 15
ELSE 20 END
#2
20
You can use a case statement in an update as follows...
您可以在以下更新中使用case语句……
UPDATE Employee
SET Age = CASE WHEN (age < 20) THEN 15
ELSE 20 END
#1
68
I think what you want is:
我认为你想要的是:
UPDATE EMPLOYEE
SET age =
CASE WHEN AGE < 20 THEN 15
ELSE 20 END
#2
20
You can use a case statement in an update as follows...
您可以在以下更新中使用case语句……
UPDATE Employee
SET Age = CASE WHEN (age < 20) THEN 15
ELSE 20 END