MS Access sql - 更新查询语法

时间:2017-02-25 12:24:13

标签: vba ms-access

似乎是一个sql更新查询的小问题。但我无法理解这个问题。不太熟悉sql。

根据选择,复制表中的选定行(7DARphases)并将其插入另一个表(7tblDAR)。并且应使用从表单中获取的固定值(PID)更新所有插入行的项目ID(PRJID列)。 问题是:我在需要在添加行的PRJID列中插入固定值的部分遇到语法问题。

代码是:

Set dbs = CurrentDb

PID = Me.PRJID.Value

sqlstr = "INSERT INTO 7tblDAR (Phase, Deliverable, Link_PIM_temp, Link_PIM_WB, Description, Accept_criteria, Deliv_type, TollgateID, Workstream, Accountable, ClientRACI) SELECT [7DARphases].Phase, [7DARphases].Deliverable, [7DARphases].Link_PIM_temp, [7DARphases].Link_PIM_WB, [7DARphases].Description, [7DARphases].Accept_criteria, [7DARphases].Deliv_type, [7DARphases].TollgateID, [7DARphases].Workstream, [7DARphases].Accountable, [7DARphases].ClientRACI FROM 7DARphases WHERE ((([7DARphases].SolType) Like '*2PP*')) ORDER BY [7DARphases].Phase, [7DARphases].Deliverable;"

sqlUpdt = "update 7tblDAR set PRJID =  '" & Me.PRJID.Value & "' from 7tblDAR where tblDAR.PRJID = """""


dbs.Execute sqlstr, dbFailOnError

dbs.Execute sqlUpdt, dbFailOnError

'sqlstr'工作正常并插入行。 但'sqlUpdt'给出错误:
“运行时错误3075:查询表达式中的语法错误(缺少运算符)...”

你可以帮我解决这个问题。

另外,如果可能,您是否可以建议在一个查询中执行此操作。

1 个答案:

答案 0 :(得分:0)

为什么不在插入值时输入值?

sqlstr = "INSERT INTO 7tblDAR (Phase, Deliverable, Link_PIM_temp, Link_PIM_WB, Description, Accept_criteria, Deliv_type, TollgateID, Workstream, Accountable, ClientRACI, PRJID)
    SELECT . . .,
           '" & Me.PRJID.Value & "' 
    WHERE [7DARphases].SolType Like '*2PP*')
    ORDER BY [7DARphases].Phase, [7DARphases].Deliverable;"

这省去了以后必须更新的麻烦。