我试图使用联合查询从另外两个表中将数据插入到第三个表中,但是我得到了一个错误:
查询定义错误中别名引起的循环引用
Q1 = "Insert into Final_PQR (Onshore_Architect,Offshore,PQR_Number,Task,PQR_Type,Status,Latest_Update,Planned_Work,Comments,Remaining_Planned_hours) "
Q1 = Q1 & " Select Distinct V.Onshore_Architect,V.Offshore,V.PQR_Number,V.Task,V.PQR_Type,V.Status,V.Latest_Update,V.Planned_Work,V.Comments,V.Remaining_Planned_hours"
Q1 = Q1 & " from [Select distinct Onshore_Architect As Onshore_Architect,Offshore As Offshore,PQR_Number As PQR_Number,Task As Task,PQR_Type As PQR_Type,Status As Status,Latest_Update As Latest_Update,Planned_Work As Planned_Work,Comments As Comments,Remaining_Planned_hours As Remaining_Planned_hours from PQR_Deepika_Final"
Q1 = Q1 & " UNION Select distinct Onshore_Architect,Offshore,PQR_Number,Task,PQR_Type,Status,Latest_Update,Planned_Work,Comments,Remaining_Planned_hours from PQR_Sonal_Final"
Q1 = Q1 & "]. As V;"
CurrentDb.Execute Q1发布于 2018-01-12 11:51:14
错误是指这类别名:Offshore As Offshore、Comments As Comments。
你不能把某物化名为现在的名字。
如果删除这些内容,它可能会运行:
Q1 = "Insert into Final_PQR (Onshore_Architect,Offshore,PQR_Number,Task,PQR_Type,Status,Latest_Update,Planned_Work,Comments,Remaining_Planned_hours) "
Q1 = Q1 & " Select Distinct V.Onshore_Architect,V.Offshore,V.PQR_Number,V.Task,V.PQR_Type,V.Status,V.Latest_Update,V.Planned_Work,V.Comments,V.Remaining_Planned_hours"
Q1 = Q1 & " from [Select distinct Onshore_Architect,Offshore,PQR_Number,Task,PQR_Type,Status,Latest_Update,Planned_Work,Comments,Remaining_Planned_hours from PQR_Deepika_Final"
Q1 = Q1 & " UNION Select distinct Onshore_Architect,Offshore,PQR_Number,Task,PQR_Type,Status,Latest_Update,Planned_Work,Comments,Remaining_Planned_hours from PQR_Sonal_Final"
Q1 = Q1 & "]. As V;"
CurrentDb.Execute Q1您还应该考虑为您的子查询使用更典型的语法。当前的语法FROM [subquery]. As Alias非常奇怪。通常的语法是FROM (subquery) As Alias或FROM (subquery) Alias
发布于 2022-08-11 09:20:07
对我起作用的是增加
选择*来自(
)作为tbl
到您的查询
插入到您的表中,选择* from (选择*来自您可选择的),作为tbl order by fld
https://stackoverflow.com/questions/48224662
复制相似问题