在MS Access SQL Server链接表中通过查询传递

SumGuy

我对使用getdate()SQL Server功能的MS Access中的链接表进行查询但是,当我尝试运行查询时出现此错误:

函数中未定义的函数GetDate

如何创建允许使用SQL Server T-SQL语法的链接表?我看到这被称为a,pass through query但我不知道如何设置它以使用链接表上的连接作为传递查询。

当前使用Access2010。查询是:

select getdate()

如果有帮助,我使用了以下vba代码来生成指向SQL Server的表链接:

Function LinkTable(LinkedTableAlias As String, Server As String, Database As String, SourceTableName As String, OverwriteIfExists As Boolean, Username As String, Password As String)
    'This method will also update the link if the underlying table definition has been modified.
    If (InStr(1, LinkedTableAlias, "MSys") > 0) Then
        Log "Skipping " & LinkedTableAlias
        Exit Function
    End If
    'The overwrite parameter will cause it to re-map/refresh the link for LinktedTable Alias, but only if it was already a linked table.
    ' it will not overwrite an existing query or local table with the name specified in LinkedTableAlias.

    'Links to a SQL Server table without the need to set up a DSN in the ODBC Console.
    Dim tdfLinked As DAO.TableDef

    ' Open a database to which a linked table can be appended.
    Dim dbsCurrent As Database
    Set dbsCurrent = CurrentDb()

    'Check for and deal with the scenario ofthe table alias already existing
    If TableNameInUse(LinkedTableAlias) Then
        'If InStr(dbsCurrent.TableDefs(LinkedTableAlias).Connect, "AccessBackup") Then
        '    Exit Function
        'End If

        If (Not OverwriteIfExists) Then
            Log "Can't use name '" + LinkedTableAlias + "' because it would overwrite existing table."
            Exit Function
        End If
        'delete existing table, but only if it is a linked table
        'If IsLinkedTable(LinkedTableAlias) Then
            dbsCurrent.TableDefs.Delete LinkedTableAlias
            dbsCurrent.TableDefs.Refresh
        'Else
        '    Log "Can't use name '" + LinkedTableAlias + "' because it would overwrite an existing query or local table."
        '    Exit Function
        'End If
    End If

    'Create a linked table
    Set tdfLinked = dbsCurrent.CreateTableDef(LinkedTableAlias)
    tdfLinked.SourceTableName = SourceTableName

    tdfLinked.Connect = "ODBC;DRIVER={SQL Server};SERVER=" & Server & ";DATABASE=" & Database & ";UID=" & Username & ";PWD=" & Password & ";"

    On Error Resume Next
    dbsCurrent.TableDefs.Append tdfLinked
    If (err.Number = 3626) Then 'too many indexes on source table for Access
            err.Clear
            On Error GoTo 0

            If LinkTable(LinkedTableAlias, Server, Database, "vw" & SourceTableName, OverwriteIfExists, Username, Password) Then
                Log "Can't link directly to table '" + SourceTableName + "' because it contains too many indexes for Access to handle. Linked to view '" & "vw" & SourceTableName & "' instead."
                LinkTable = True
            Else
                Log "Can't link table '" + SourceTableName + "' because it contains too many indexes for Access to handle. Create a view named '" & "vw" & SourceTableName & "' that selects all rows/columns from '" & SourceTableName & "' and try again to circumvent this."
                LinkTable = False
            End If
            Exit Function
    End If
    On Error GoTo 0

    '** Turn on error handling
  On Error GoTo ErrorHandler:
    tdfLinked.RefreshLink


    LinkTable = True

    Exit Function
ErrorHandler:
    Log "refreshlink failed for " & tdfLinked.Name
    LinkTable = True
尼克·麦克德麦德

我不太明白这句话:

如何创建允许使用SQL Server T-SQL语法的链接表?

但这是将现有的MS Accessquerydef转换为传递查询的方式:

走在查询到设计模式,按下Query菜单命令,然后SQL SpecificPass Through

查看此截图。

http://www.mssqltips.com/sqlservertip/1482/microsoft-access-pass-through-queries-to-sql-server/

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

MS Access SQL插入查询

来自分类Dev

使用SQL查询在MS Access中获取表结构?

来自分类Dev

MS ACCESS SQL查询计数不同

来自分类Dev

MS Access SQL查询IP地址范围

来自分类Dev

使用MS Access插入SQL Server

来自分类Dev

取消嵌套的MS Access SQL查询嵌套

来自分类Dev

从MS Access执行SQL Server存储过程

来自分类Dev

MS Access,更新查询不会更新链接表

来自分类Dev

将SQl查询转换为MS Access

来自分类Dev

带VBA的MS Access链接表

来自分类Dev

使用SQL查询在MS Access中获取表结构?

来自分类Dev

MS Access数据库SQL查询

来自分类Dev

在MS ACCESS 2010中创建表-使用Oracle SQL查询

来自分类Dev

MS Access SQL查询IP地址范围

来自分类Dev

使用MS Access插入SQL Server

来自分类Dev

通过Access连接到SQL Server后端的MS Access?

来自分类Dev

通过SQL查询计算MS Access中的空白字段

来自分类Dev

从MS Access更新SQL Server中的表的列

来自分类Dev

在MS Access SQL查询中合并行

来自分类Dev

MS Access SQL查询中的奇怪IIF

来自分类Dev

MS Access:来自SQL Server的只读链接表?

来自分类Dev

我无法在Access前端和MS-SQL后端之间建立新的链接表

来自分类Dev

带通配符的SQL连接表(MS Access)

来自分类Dev

MS Access sql - 更新查询语法

来自分类Dev

MS Access SQL 日期范围查询

来自分类Dev

比较 MS Access SQL 查询中的两个表

来自分类Dev

MS Access - 更新 SQL 查询错误 3061

来自分类Dev

MS Access 链接表到 SQL Server

来自分类Dev

来自 MS Access 的 SQL 复制查询