用于更新库存水平的SQL

时间:2012-10-10 13:22:59

标签: sql database ms-access

运行以下代码时出现此错误:

Error

Dim sqlSCIQty As String
Dim sqlSCQty As String

sqlSCIQty = "UPDATE [products/stock] INNER JOIN [Stock Conversion Items] " & _
"ON [products/stock].[Product Code] = [Stock Conversion Items].[Result PC] " & _
"SET [Stock Level] = ([Stock Level] + [Quantity]) " & _
"WHERE [Stock Conversion Items].[CutID] = " & Me.txtPCutID.Value & ";"

sqlSCQty = "UPDATE [products/stock] INNER JOIN [Stock Conversion] " & _
"ON [products/stock].[Product Code] = [Stock Conversion].[Source PC] " & _
"INNER JOIN [Stock Conversion Items] " & _
"ON [Stock Conversion].[SCID] = [Stock Conversion Items].[SCID] " & _
"SET [Stock Level] = ([Stock Level] - [Stock Conversion].[Quantity]) " & _
"WHERE [Stock Conversion Items].[CutID] = " & Me.txtPCutID.Value & ";"

Set db = CurrentDb
db.Execute sqlSCIQty, dbFailOnError
db.Execute sqlSCQty, dbFailOnError
Set db = Nothing

我知道第一个语句可以运行并且运行正常,但是第二个语句引发了这个错误,我不熟悉这样复杂的更新语句,所以任何有任何SQL知识的人都可以发现任何内容吗?

提前致谢,
Bob P

1 个答案:

答案 0 :(得分:1)

你可以尝试这样

sqlSCQty = "UPDATE (([products/stock] INNER JOIN [Stock Conversion] " & _
"ON [products/stock].[Product Code] = [Stock Conversion].[Source PC]) " & _
"INNER JOIN [Stock Conversion Items] " & _
"ON [Stock Conversion].[SCID] = [Stock Conversion Items].[SCID]) " & _
"SET [Stock Level] = ([Stock Level] - [Stock Conversion].[Quantity]) " & _
"WHERE [Stock Conversion Items].[CutID] = " & Me.txtPCutID.Value & ";"

如果ms-access

中有多个加入,则需要括号