Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a temp table dynamiclly?
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Creating a temp table dynamiclly?
Miscellaneous
Thread ID:
01058813
Message ID:
01058813
Views:
63
The following dynamic SQL script works for creating a table on the fly but if I change the select @tmpTblNm = 'tmpABC' to select @tmpTblNm = '#tmpABC'
it will not create the temp table. Can anyone help on creating a temp table dynamiclly?

declare @tmpTblNm varchar(40),
@str varchar(1000)

select @tmpTblNm = 'tmpABC'
select @str = ''

-- Create a temp table to hold the current page of data
-- Add an ID column to track the current row
select @str = 'Create Table '+ @tmpTblNm +
' ( row_id int IDENTITY PRIMARY KEY,
customerID int,
customerName varchar(40),
address1 varchar(40),
city varchar(25) )'

exec (@str)
Software engineers are trained to read and understand code; they are not trained in mind reading. Document the purpose not just the functionality.
Next
Reply
Map
View

Click here to load this message in the networking platform