【发布时间】:2017-02-03 22:29:03
【问题描述】:
以下代码调用 passthru 查询 (PTQ) 并应显示一条消息,指示受影响的记录数:
With CurrentDb
.Execute "ArticleClientTmpUpdate"
MsgBox .RecordsAffected & " records updated"
End With
PTQ 做了一个简单的合并:
merge into dbo.ArticlesClients ac
using (select * from dbo.ArticlesClientsTmp) act on ac.IdArticle = act.IdArticle and ac.IdClient = act.IdClient
when matched then
update SET ac.IdArticle = act.[idArticle],
ac.IdClient = act.[idclient],
ac.RefClient = act.[refClient],
ac.Commentaire = act.[commentaire],
ac.ModDate = getdate()
when not matched then
insert (idArticle, idClient, RefCLient, Commentaire)
values (act.idArticle, act.idClient, act.RefCLient, act.Commentaire);
在清空目标表后从 SSMS 执行时,我可以看到 9200 行受到影响(例如创建)。
使用上述 VBA 执行相同的合并时,它显示“导入了 0 条记录”,但会执行该作业并创建 9200 条记录。
有什么解释吗?有解决该问题的方法吗?使用 ADO connection 而不是 DAO CurrentDb 会更好吗?
【问题讨论】:
标签: sql-server ms-access vba dao