Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a temp table dynamiclly?
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01058813
Message ID:
01058815
Views:
15
A temp table created in a stored procedure is deleted when stored procedure finishes. If you create a temp table in the calling sproc than you can access it in the called sproc.


>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)
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform