-1

如果这样的东西已经发布或者只是一个简单的修复,我很抱歉,但我一直在四处寻找,似乎无法找到解决这个问题的方法。我正在使用 vba: ms 访问,并且我试图通过运行查询来比较不同数据库中的两个相同的表。我一直在尝试制作脚本,以便它可以在只需要用户输入的不同数据库上运行。然而,通过这个过程,我似乎不断收到一个错误,内容如下:

select 语句包含拼写错误或丢失的保留字或参数名称。

LinkUserTable 函数基本上根据用户输入从另一个数据库创建链接表。下面是子程序:

Sub LinkTables()
        Dim sTable1 As String
        Dim sTable2 As String
    sTable1 = LinkUserTable
    sTable2 = LinkUserTable

    vars_sql = "SELECT " & sTable1 & ".[f_ptid]," & sTable1 & ".[f_flag]," & sTable1 & ".[f_user]," & sTable1 & ".[f_brief]," & sTable1 & ".[f_gid]," & sTable1 & ".[f_vco]," & sTable1 & ".[f_dtype]," & sTable1 & ".[f_precs]," & sTable1 & ".[f_addr]," & sTable1 & ".[f_ndim]," & sTable1 & ".[f_sys]," & sTable1 & ".[f_unit]," & sTable1 & ".[f_value]," & sTable1 & ".[f_pred]," & sTable1 & ".[f_bflag]," & sTable1 & ".[f_dim1]," & sTable1 & ".[f_dim2]," & sTable1 & ".[f_dim3]," & sTable1 & ".[f_bound]," & sTable1 & ".[f_size]," & sTable1 & ".[f_updat]," & sTable1 & ".[f_time]," & sTable1 & ".[f_ldes]," & sTable1 & ".[f_sflag]," & sTable1 & ".[f_tflag]," & sTable1 & ".[rid]" + _
                    "FROM" + sTable1 + " AS LEFT JOIN " + sTable2 + " AS ON sTable1.[f_ptid] = sTable2.[f_ptid]" + _
                    "WHERE (((" & sTable2 & ".[f_ptid]) Is Null))" 


If CheckQuery("new_old") = "Yes" Then
            DoCmd.DeleteObject acQuery, "new_old"
        End If

Set qdf = CurrentDb.CreateQueryDef("new_old", vars_sql)

End Sub

我只是想知道基于此可能会导致此错误的问题是什么?所有字段都在两个数据库中,都具有相同的属性(只是不同的数据)。如果缺少信息,我深表歉意,如果需要,我可以提供更多信息。

4

2 回答 2

0

正确的语法是LEFT JOIN,不是AS LEFT JOIN

例外情况是,如果您想给表一个别名,在这种情况下,您会这样做AS Alias LEFT JOIN......但是,在这种情况下,您不想这样做,因为您使用的是[table].[columnname]语法)。

于 2013-07-12T18:00:05.710 回答
0

赋值的第二行在vars_sql字符串中包含一些表变量:

" AS ON sTable1.[f_ptid] = sTable2.[f_ptid]"

上面应该是这样的:

" AS ON " + sTable1 + ".[f_ptid] = " + sTable2 + ".[f_ptid]"  
于 2013-07-12T18:02:01.240 回答