Update Query from a Lookup Query

帅比萌擦擦* 提交于 2019-12-06 20:59:27

Another possibility in MS Access (object names borrowed from Tomalak answer):

UPDATE tblStarting_Data, qryIDPerCustomer
SET tblStarting_Data.CustomerID=qryIDPerCustomer.CustomerID
WHERE tblStarting_Data.TEMPCustomer=qryIDPerCustomer.CustomerName

I think a JOIN will help you:

UPDATE 
  tblStarting_Data AS sd 
  INNER JOIN qryIDPerCustomer AS qc ON sd.TEMPCustomer = qc.CustomerName
SET 
  sd.CustomerID = qc.CustomerID;

This can be expressed as a correlated sub-query as well (though the join syntax is preferable):

UPDATE 
  tblStarting_Data
SET 
  CustomerID = (
    SELECT  CustomerID 
    FROM    qryIDPerCustomer
    WHERE   CustomerName = tblStarting_Data.TEMPCustomer
  )

No need for a loop, both statements will update all records in tblStarting_Data in one step.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!