I have created a table in sql server and the tabel has Information of an Employee. There is a column to determine whether the Employee is male or female. i.e Male or Female. Now I need to convert all Male to Female and all Female to Male?

The table structure is:

CREATE TABLE Employee (
FName char(50), 
LName char(50), 
Address char(50),
Gender char(10),
Birth_Date date)
有帮助吗?

解决方案

Freaky.

as a basic example, something like this:

update employees
set
    gender = case gender 
        when 'Male' then 'Female'
        when 'Female' then 'Male'
        else 'Other' end

其他提示

this should work:

UPDATE dbo.Employee
SET Gender =    
    CASE
        WHEN (Gender = 'Female')
            THEN 'Male'
        WHEN (Gender = 'Male')
            THEN 'Female'
    END

Use this script

UPDATE [Employee]
SET [Gender] = CASE [Gender]
WHEN 'Male' THEN 'Female'
WHEN 'Female' THEN 'Male'
END
update employee
set gender=case when gender='Male' then 'Female'
when gender='female' then 'male' end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top