Write A Query :
We have a table EmpMaster Which have two column Name varchar(50), Gender char(1).
We want to Update Gender Column . Means Where Gender Is 'M' Update With 'F' and 'F' Update with 'M'

 Posted by Anu.Malik on 7/6/2012 | Category: Sql Server Interview questions | Views: 2977 | Points: 40
Answer:

--Create Table

CREATE TABLE EMPMaster(
[EMP_Name] [varchar](50) ,
Gender Char(1)
)

--Insert Record
Insert INTO EMPMaster Values('AA','M')
Insert INTO EMPMaster Values('BB','M')
Insert INTO EMPMaster Values('CC','F')
Insert INTO EMPMaster Values('DD','M')
Insert INTO EMPMaster Values('EE','F')
Insert INTO EMPMaster Values('FF','F')

--Update Query

Update EMPMaster SET Gender=Case When Gender='M' Then 'F'
Else 'M' END


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response

More Interview Questions by Anu.Malik