SQL Journey

  • Your Email ID:

    Join 6 other followers

  • Top Rated

  • Bookmarks

  • Twitter Updates

  • Blog Stats

    • 16,734 hits
  • SocialVibe


Posts Tagged ‘Sql Update’

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.

Posted in Database Development, General, Interview Questions | Tagged: , , , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.