我試圖更新我的零件表,其中item_class = HW
和我無法正確理解。任何人都可以看到我的語法有什麼問題。試圖用update語句和where子句更新我的數據庫表中的零件表
update part
set unit_price = unit_price + 1.05
where item_class = ' HW ' ;
它提供了沒有錯誤,但它不更新正確的行。它說它實際上需要更新4行時將更新0行。
我試圖更新我的零件表,其中item_class = HW
和我無法正確理解。任何人都可以看到我的語法有什麼問題。試圖用update語句和where子句更新我的數據庫表中的零件表
update part
set unit_price = unit_price + 1.05
where item_class = ' HW ' ;
它提供了沒有錯誤,但它不更新正確的行。它說它實際上需要更新4行時將更新0行。
你可以有錯誤的空間,嘗試使用
update part
set unit_price = unit_price + 1.05
where item_class like '*HW*' ;
或
update part
set unit_price = unit_price + 1.05
where item_class like '* HW *' ;
或
update part
set unit_price = unit_price + 1.05
where item_class = 'HW' ;
不知道你的數據很難說,但我看到幾個可能出現的問題。一個是「HW」周圍的空間。根據該領域的內容,很難確切地知道哪裏的條款是正確的。如果硬件是較長字符組的一部分(人們有時會錯誤地在逗號字段中存儲逗號分隔列表),則可能需要使用LIKE函數。或者可能是刪除不需要的空間將解決這個問題。因此,從select語句開始:
Select * from part where item_class = ' HW ' ;
Select * from part where item_class = 'HW' ;
Select * from part where item_class like '*HW' ;
Select * from part where item_class like 'HW*' ;
Select * from part where item_class like '*HW*' ;
一旦找到返回所需記錄的那個,然後在更新語句中使用它。
別的東西,我看到了可能導致的問題是:
set unit_price = unit_price + 1.05
如果單價可以爲NULL,則需要將其轉換成對於和工作0值。否則,NULL加上任何金額= NUll。以下可以工作。
set (IIf([unit_price] Is Null, 0, [unit_price]))+1.05
是的第二個工程。那是無意的空間。謝謝 – Clay
你有兩個空間在你的HW左右。是這樣嗎? – scaisEdge
不是非常感謝你 – Clay
請將你的問題標題改爲有意義的東西。你已經重複了標籤,這是完全無用的,並且刪除它們留下*(更新語句)*,這是無用的。您的標題應該解釋您所問的問題或您遇到的問題,這些問題對於將來在搜索結果中看到它的用戶會有意義。 –