문제

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