Update MSAccess table from another Access table using SQL

一个人想着一个人 提交于 2019-12-17 20:27:41

问题


I am trying to update table Original with the values in Final. I'm a newb to SQL, but I have been at this for two hours trying to change various samples to fit my needs. I am using Access 2007.

UPDATE 
  Original o
SET 
  o.[Assest Description] = (
    SELECT f.[Assest Description] FROM Original o, Final f 
    WHERE o.[Assest No] = f.[Assest No])
WHERE o.[Assest No] = Final.[Asset No]

回答1:


I'm not sure your select statement returns only one row. If you want to perform an update on a table using a select statement for assignment, you must be sure that it returns only one row.

Besides that, you may consider the next solution:

update 
   Original as o
   inner join Final as f on o.[Assest No] = f.[Assest No]
set
   o.[Assest Description] = f.[Assest Description]

Notice that this will only work correctly if both [Assest no] is a unique key in both Original and Final tables, and they are properly related.




回答2:


Try this

UPDATE o 
SET o.[Assest Description] =  f.[Assest Description]
FROM Original o, Final f WHERE o.[Assest No] = f.[Assest No]



回答3:


I don't know if this should be an answer or a comment but since it stands alone I'm writing it as an answer. Access is horribly picky. If you fully qualify the name of the field you are updating it may fails. If you don't fully qualify joins tables and fields it may come back with "join not supported". I say may because it's likely slightly different versions will do something different. At least that's my experience. So my answer is start with Create->Query Design. Pick the two tables and get the select working correctly. Then modify it to an update query and make the update to of the column(s) you want to update the fields from the table you want to update from. Then switch to SQL view and use that as the model to build your query in VBA. I had a syntactically correct SQL statement but until I did this and then matched the qualifying vs non-qualified field names EXACTLY it claimed JOIN IS NOT SUPPORTED.



来源:https://stackoverflow.com/questions/12737221/update-msaccess-table-from-another-access-table-using-sql

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