Table
ID DESC
1 Male
2 Male
3 Male
4 Female
5 Female
6 Female
7 Female
我需要使用一個更新語句更新男性到女性和女性到男性。請對此建議。提前致謝。是否有可能使用單個更新語句更新包含多個條件的表值
Table
ID DESC
1 Male
2 Male
3 Male
4 Female
5 Female
6 Female
7 Female
我需要使用一個更新語句更新男性到女性和女性到男性。請對此建議。提前致謝。是否有可能使用單個更新語句更新包含多個條件的表值
對於SQL Server
update tbl
SET DESC = CASE
WHEN DESC= 'Male' THEN 'Female'
WHEN DESC = 'Female' THEN 'Male'
ELSE DESC
END
是的,你可以這樣做,使用情況下聲明
UPDATE TABLE
SET DESC = CASE WHEN DESC = 'MALE' THEN 'Female' WHEN DESC = 'Female' THEN 'MALE' ELSE DESC END
試試這個
UPDATE Table
SET DESC = CASE
WHEN DESC= 'Male' THEN 'Female'
WHEN DESC = 'Female' THEN 'Male'
ELSE DESC
END
出把儘可能遵循
ID DESC
1 Female
2 Female
3 Female
4 Male
5 Male
6 Male
7 Male