Advanced SQL – Conditionally Updating Update Command
MS SQL Server
UPDATE Emp
SET incentive = CASE
WHEN salary >=1500 and salary <5000 THEN
3000
WHENsalary> 5000 andsalary<10000 THEN
CASE
WHEN firstname in (‘AJAY’) THEN
5000
END
ELSE incentive
END;
SELECT * FROM EMP;
Output
Conditionally Updating Data From Another Table
UPDATE EMPdetail SET Grad = (SELECT
CASE WHEN salary >=1500 and salary <5000 THEN
‘B’
WHEN salary>5000 and salary<10000 THEN
CASE
WHEN firstname in (‘AJAY’) THEN
‘A’
END
ELSE
Grad
END)