What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 63632 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > SQL Server Interview Questions > Write A Query : We have a table EmpMas ...

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'

Interview question and answer by: Anu.Malik | Posted on: 7/6/2012 | Category: SQL Server Interview questions | Views: 704 | | 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 
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Anu.Malik

    Even more ... | Submit Interview Questions and win prizes!


    About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
    General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
    Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 9:08:59 AM