Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Can't I join with a temporary table?

Author  Topic 

xdk1x
Starting Member

9 Posts

Posted - 2004-06-07 : 08:36:34
Hi!

I want to JOIN a table with a temporary created table within a procedure. The table is declared as followed:

DECLARE @tmpPooldat TABLE (P1 CHAR(6), P2 CHAR(6), P3 CHAR(6), P4 CHAR(6), P5 CHAR(6), P6 CHAR(6))

The JOIN Statement:

SELECT ...
FROM tbSchaeden JOIN @tmpPooldat
ON tbSchaeden.ZugJahrMonat = @tmpPooldat.P1;

The error message:

Server: Nachr.-Nr. 137, Schweregrad 15, Status 2, Zeile 46
Must declare the variable '@tmpPooldat'.

Can't I join with a temporary table?

Thanks for your help!

Daniel

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-06-07 : 08:42:17
Is your select inside of dynamic SQL? If it is, then it won't work. Also, your statement won't work, but this will:

SELECT *
FROM tbSchaeden ts JOIN @tmpPooldat tp
ON ts.ZugJahrMonat = tp.P1


MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2004-06-07 : 08:43:06
Alias the temporary table and it should work fine.

-------
Moo. :)
Go to Top of Page

xdk1x
Starting Member

9 Posts

Posted - 2004-06-07 : 08:48:48
Thanx guys!!! Now it works...
Go to Top of Page
   

- Advertisement -