SQL UPDATE / WHERE帮助...更新WHERE未定义的列

时间:2014-01-31 19:13:35

标签: vba ms-access ms-access-2007 access-vba

基本SQL UPDATE和Access 2007 vba问题。有人可以向我解释为什么这个查询也在更新BoxType“60ct托运人托盘”而不只是更新WHERE声明中声明的60ct托运人件?谢谢!

ElseIf Me!txtBoxType = "60ct Shipper Tray" Then

 'Cases that use a 60tray are more complicated. They use 1 each of the base, header, and display
 'aswell as 3 shelves.

qdf.SQL = "UPDATE tblBoxList Set Qty = (Qty+(" & Me!txtQtyChange & ")) WHERE BoxType = '60ct Shipper Base' OR '60ct Shipper Header' OR '60ct Shipper Display';"
qdf.Execute dbFailOnError

1 个答案:

答案 0 :(得分:2)

您需要在OR的每个条件中包含字段名称。使用SELECT查询来计算WHERE子句逻辑。

SELECT *
FROM tblBoxList 
WHERE
       BoxType = '60ct Shipper Base'
    OR BoxType = '60ct Shipper Header'
    OR BoxType = '60ct Shipper Display'

您可能更喜欢这种方法。

WHERE BoxType IN
    (
        '60ct Shipper Base',
        '60ct Shipper Header',
        '60ct Shipper Display'
    )