Condition based Update in SQL Server
Posted by Prashant on June 9, 2010
In SQL Server conditional update can be done using CASE.
--Update employee monthly commission based on their rating UPDATE Employees SET Comm = CASE WHEN (Rating between 2 and 3)THEN (Salary * 0.1) WHEN (Rating between 3.1 and 4)THEN (Salary * 0.15) WHEN (Rating between 4.1 and 5)THEN (Salary * 0.25) ELSE 0.0 END
This example is just to demonstrate a scenario. Here it examines the employee rating to determine what should be the updated Commission. The CASE expression uses range of employee rating to update the commission amount.