General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Dynamically naming local temp tables
To all,
I'm writing a series of stored procedures in SQL Server 2000. My intent is for the procedures to create one or more local temp tables. The tables' name will be dynamically created and the dynamically created table name will be passed back through an output parameter.
Issue one: What's the best way to create a unique string to be used as a temp table name?
Issue two: How can I get SQL Server to accept the temp table name in a query?
For example:
DECLARE @cMyTempTable VarChar(25)
SET @cMyTempTable = [unique string]
SELECT *
INTO #@cMyTempTable
FROM dbo.MySourceTable
When I try this, SQL Server gets very unhappy with the INTO clause.
All of this is well established methodology in FoxPro, my milk language, but I can't find any indication of how to do this with SQL Server.
Any help?
TIA
Thom C.
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only