How to create temp tables in SQL Server via MS Access

后端 未结 2 1188
逝去的感伤
逝去的感伤 2021-01-24 06:15

I have an ODBC connection to SQL Server. I need to process data within Access, but it takes too long. My idea is to push this data to a SQL Server temp table and have SQL Server

2条回答
  •  醉话见心
    2021-01-24 06:24

    Here is a snippet of VBA code I used to call a DB2 stored procedure. The same technique should work for any DDL statement. To do this, create a pass-through query and put your CREATE TABLE #tblname... statement as its SQL text.

    IMPORTANT: Then open the query's property sheet and set the 'Returns Records' property to "No".

    Dim qdf As QueryDef
    Set qdf = CurrentDb.QueryDefs("qry_SP_CHANGE_COLUMN")
    qdf.Connect = CurrentDb.TableDefs("SCHEMA_tblName").Connect
    qdf.SQL = "call SCHEMA.SP_CHANGE_COLUMN(...)"
    qdf.Execute dbFailOnError
    qdf.Close
    Set qdf = Nothing
    

    Note, you probably won't have to change your SQL text. You can just leave that in the query def if the table structure never changes.

    The challenge for you is that you must use the same connection for any operations against the temp table. The minute the connection is closed, your temp table will vanish because it's a local temp table, and it's only visible to that one connection. You can avoid this by using '##', global temp tables, if you have rights to do that.

提交回复
热议问题