我正在尝试使用联合查询将数据插入另外两个表的第三个表中,但是我收到错误:
由查询定义错误中的别名引起的循环引用
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
答案 0 :(得分:1)
错误是指这些别名: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