Saturday, July 12, 2014

CASE Statement in SQL

Calculation of Bonus by using CASE statement.

Select statement with CASE is used to insert the logical conditions in the statement. Oracle provide us the facility to insert logical condition while selection from the database. Below statement is also used to insert the record in the table.

In following example, Logical condition is applied in JOB field while calculation of bonus with CASE statement.

In case of manager bonus will be 10% and in case of salesman bonus will be 8% and in case of clerk bonus will be 6%.

SELECT EMPNO,ENAME,JOB,
  CASE JOB WHEN   'MANAGER'   THEN SAL*10/100
                     WHEN   'SALESMAN'  THEN SAL*8/100
                     WHEN   'CLERK'           THEN SAL*6/100
       ELSE SAL* 2/100  END  BONUS
       FROM EMP;







No comments:

Post a Comment