簡體   English   中英

SQL Update語句(MS ACCESS)

[英]SQL Update statement (MS ACCESS)

我執行了以下語句,但是它僅更新除Assasin信條(空白值)以外的所有價格行。 此外,我表中其他未在下面定義的行也被清除(空白值)。 如果我更新2種產品,它似乎正常工作。 有什么事嗎

(僅用於顯示包裝的換行符)

"UPDATE Products SET Price = IIf(Product = 'Crysis Wars'," +
CrysisWarsInput.Text +
", IIf(Product = 'Far Cry 2'," + FarCry2Input.Text +
", IIf(Product = 'Day of Defeat Source'," + DODSourceInput.Text +
", IIf(Product = 'GTA 4'," + GTA4Input.Text +
", IIf(Product = 'Asassins Creed'," + AssassinsCreedInput.Text + ")))))";

也許是因為您誤記了“刺客信條”? 設置WHERE子句,或在最后一個IIF中將Price添加為默認值

"UPDATE Products SET Price = " +
"  IIf(Product = 'Crysis Wars',"          + CrysisWarsInput.Text +
", IIf(Product = 'Far Cry 2',"            + FarCry2Input.Text +
", IIf(Product = 'Day of Defeat Source'," + DODSourceInput.Text +
", IIf(Product = 'GTA 4',"                + GTA4Input.Text +
", IIf(Product = 'Assasins Creed',"       + AssassinsCreedInput.Text + ", Price)))))";
  • 表中未在下面定義的其他行

這就是WHERE子句的目的,以限制要更新的記錄。

"UPDATE Products SET Price = " +
"  IIf(Product = 'Crysis Wars',"          + CrysisWarsInput.Text +
", IIf(Product = 'Far Cry 2',"            + FarCry2Input.Text +
", IIf(Product = 'Day of Defeat Source'," + DODSourceInput.Text +
", IIf(Product = 'GTA 4',"                + GTA4Input.Text +
", "                                      + AssassinsCreedInput.Text + ")))) +
" WHERE Product in ('Crysis Wars','Far Cry 2','Day of Defeat Source'," +
"  'GTA 4','Assasins Creed')";

您也可以使用SWITCH語句代替多個IIF。

重新刺殺信條-可能是錯字。 非常仔細地查看單元格和查詢中的值-例如,是刺客還是刺客?

重新其他(不在查詢中); 您需要添加一個“ where”子句,否則它適用於表中的每一行; 這就是SQL的工作方式...我猜這里最好使用IN過濾器。 例子

where Product in ('some title', 'another title', ...)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM