Sql tmp table and reports

N

Newbie

Hi

How can I use a temp table created in SQL Server 2000 as the basis for a
report in Access?

Thanks
 
R

Ron Kunce

SQL Server temp tables are dropped when the procedure that creates them goes
out of scope or when the session connection ends depending on whether you
use a single '#' or double '##' at the beginning of the tables name. If
your connection to SQL server is contiguous (i.e., the report and the
procedure that created the table both run within the same session
connection) then a session temp table can work.

However, to be on the safe side, just create a standard table with 'tmp'
prefix and set your procedure to drop any existing table with the same name
before you recreate it. You can easily drop and create your temp table
using a SELECT..INTO SQL query like the following example:

Alter Procedure procPrintLienRenewals
AS
DROP TABLE dbo.ttmpLienRenewals
SELECT DISTINCT V.ReferralID, V.PropertysSequenceNumber,
V.County, O.LOName, V.CaseCtyCode,
C.ConsultantsName, V.CaseName,
V.CaseID, V.LienFileNumber,
V.LienFileDate, V.PropertysCounty,
V.PropertysState, V.LienPrintDate
INTO ttmpLienRenewals
FROM tblFieldConsultants C LEFT OUTER JOIN tblLocalOffices O ON
C.ConsultantsID = O.FieldConsultantsID RIGHT OUTER JOIN
vuePullLienRenewals V ON O.LocalOfficeID = V.County
ORDER BY V.County, V.CaseName;

Or you can choose to have the report to send a command to drop the table
when the report closes if you don't want it to stick around between runs.

Ron Kunce
 
R

Ron Kunce

ADDENDUM: You have to be the DBO or a member of the sysadmin group to Drop
the table. Therefore, if a non-sysadmin user is running the procedure, you
can change the DROP TABLE to a TRUNCATE TABLE to remove all rows before
recreating it.
 
J

Jeff Johnson [MVP: VB]

SQL Server temp tables are dropped when the procedure that creates them goes
out of scope or when the session connection ends depending on whether you
use a single '#' or double '##' at the beginning of the tables name.

I thought it was "the session connection ends" (for # tables) or "the server
is restarted" (for ## tables).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top