Microsoft KB Archive/287728

= How to create and use temporary tables with Access 2002 client/server =

Article ID: 287728

Article Last Modified on 11/14/2007

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q287728



Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access project (.adp).

For a Microsoft Access 2000 version of this article, see 232379.

IN THIS TASK
SUMMARY
 * How to Create a Temporary Table
 * How to INSERT and SELECT Records from a Temporary Table and Display the Data in the User Interface

REFERENCES



SUMMARY
Using Access Client/Server, you can create temporary tables in both SQL Server and Microsoft SQL Server 2000 Desktop Engine. Even though you cannot see the tables in the Tables pane of the Database window, the temporary tables are available for use through stored procedures and other means.

NOTE: The previous version of Microsoft SQL Server 2000 Desktop Engine is named Microsoft Data Engine (MSDE).

When you create a temporary table in a database hosted by Microsoft SQL Server 2000 Desktop Engine or SQL Server, the table is stored in the tempdb database. However, an Access project will connect to only one back-end database at a time (generally, a user database). Because temporary tables and user tables are stored in different databases, Access Client/Server will not display both. However, temporary tables are accessible from a user database through stored procedures and triggers.

The following example demonstrates:


 * How to create a temporary table through stored procedures.
 * How to insert data into the table and display the data in the temporary table in the user interface.

back to the top

How to Create a Temporary Table
 Open an Access project that is connected to a Microsoft SQL Server Desktop 2000 Engine or SQL Server database. In the Database window, click Queries under Objects. Click New. In the New Query dialog box, click Create Text Stored Procedure, and then click OK.  Type the following script into the new stored procedure: CREATE PROCEDURE CreateATable AS CREATE TABLE ##ThisIsATest (   MyPK int IDENTITY (1,1),    MyChar char(10) )  Save the stored procedure with the default name of CreateATable, and then close it. To execute the stored procedure, double-click on its name, and then in the Database window, click Tables. Examine the table list, and note that the temporary table ##ThisIsATest is not in the list.</li></ol>

back to the top

How to INSERT and SELECT Records from a Temporary Table and Display the Data in the User Interface
<ol> After you have completed the steps in the &quot;Create a Temporary Table&quot; section, click Queries under Objects.</li>  Click New. In the New Query dialog box, click Create Text Stored Procedure, click OK, and then type the following script: CREATE PROCEDURE InsertSelect AS SET NOCOUNT ON INSERT ##ThisIsATest Values('1stRecord') INSERT ##ThisIsATest Values('2ndRecord') SELECT * FROM ##ThisIsATest </li> Save the stored procedure with the default name of InsertSelect, and then close it.</li> To execute the stored procedure, double-click on its name, and note that you are presented with a view of the temporary table ##ThisIsATest. It contains the two records inserted by the stored procedure.</li></ol>

back to the top

<div class="references_section">