UPDATE dbo.TestStudents SET LASTNAME = ( CASE WHEN (LASTNAME = 'AAA') THEN 'BBB' WHEN (LASTNAME = 'CCC') THEN 'DDD' WHEN (LASTNAME = 'EEE') THEN 'FFF' ELSE (LASTNAME) END )
该语句用于此目的,但 else 条件扫描表中的每条记录。有什么办法可以让未受影响的行保持原样?
添加一个WHERE子句
WHERE
UPDATE dbo.TestStudents SET LASTNAME = CASE WHEN LASTNAME = 'AAA' THEN 'BBB' WHEN LASTNAME = 'CCC' THEN 'DDD' WHEN LASTNAME = 'EEE' THEN 'FFF' ELSE LASTNAME END WHERE LASTNAME IN ('AAA', 'CCC', 'EEE')