Change Gender value in SQL table
-
24-01-2021 - |
Frage
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)
Lösung
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
Andere Tipps
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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow