2015-11-04 81 views

回答

2

可以將此條件添加到您的where條款的更新:

UPDATE Student 
SET First = @FirstName 
WHERE First != @FirstName AND EmpId = 1 

編輯:
正如凱文Suchlicki在評論中指出,如果First爲空,null S的關係明確處理:

UPDATE Student 
SET First = @FirstName 
WHERE EmpId = 1 AND ((First != @FirstName) OR 
         (First IS NULL AND @FirstName IS NOT NULL) OR 
         (First IS NOT NULL AND @FirstName IS NULL)) 
+0

請注意現有數據和新數據中的空值,因爲NULL!='John'的計算結果爲FALSE,阻止了您想要的更新 –

+0

@KevinSuchlicki好點,謝謝!編輯它到我的答案。 – Mureinik

+0

更新學生 SET名字=姓 WHERE EMPID = 1 – user1030181