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 do the processing. I have many pass-through queries in my Access database but do not know how I can create a temp table from Access to SQL Server. Is there a way to do this using either a query or VBA code?
相关问题
- sql execution latency when assign to a variable
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
- SQL to Parse a Key-Value String
相关文章
- Entity Framework 4.3.1 failing to create (/open) a
- Code for inserting data into SQL Server database u
- SQL Server 2008 Change Data Capture, who made the
- Delete Every Alternate Row in SQL
- Linux based PHP install connecting to MsSQL Server
- SQL Azure Reset autoincrement
- How do we alias a Sql Server instance name used in
- Is recursion good in SQL Server?
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".
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.
Brian is correct that you could use a Pass-Through query to create a temporary table in the SQL Server database. I confirmed this by creating the following four pass-through queries in Access:
[ptq1 create temp table]
[ptq2 populate temp table]
[ptq3 do calculations]
[ptq4 retrieve results]
I can run each of these in succession by double-clicking them in Access' list of saved queries, and the final query returns
The stumbling block here looks like it will be how to get the data from the local Access table into the temporary table. In VBA I tried both
and
and both methods failed because they could not "see" the temporary table. (The exact same code worked when I tried to create a link to a "real" table in that same SQL Server database.) I also tried using
tbd.OpenRecordset
to create a recordset without appending the TableDef to the TableDefs collection and that failed, too.Without a link to the temporary table it seems that populating it could be problematic. I suppose one could use code like...
... to transfer the data from the local table to the temporary table row-by-row, but that could get pretty tedious for a large number of columns, and it could be rather slow for a large number of rows.
So if I was in your position I would try to make my case for having a "real" table created in the SQL Server database. It certainly would make things a lot simpler.