Pages

13 August 2016

SQL- Scenario Based Questions PART- 8

SCENARIO:

Table Employee_Details has Gender column. In this Gender column M should be updated with F and F should be updated with M.

Employee_Details



EXPECTED:

Employee_Details


SOLUTIONS (Using DECODE):

We have to update table using DECODE function as follows.


UPDATE EMPLOYEE_DETAILS

SET GENDER=DECODE(GENDER,'M','F',

                         'F','M');




SOLUTIONS (USing CASE statement ):

We have to update table using CASE  statement as follows.

UPDATE EMPLOYEE_DETAILS
SET GENDER= CASE WHEN Gender='M' THEN 'F'
                                         WHEN Gender='F' THEN 'M'
                             END;

For Other Scenario based questions, please visit below URL:
http://itjunction4all.blogspot.com/2016/08/sql-scenario-based-questions-part-5.html

If you like this post, don't forget to share and post comment.

2 comments: