stored procedures and temp tables
I have to create a 10 stored procedure as follows: In stored procedure # 1 I create temp table 1 and this temp tabl开发者_运维问答e is used in stored procedure 2 to create another temp table and this new tem table is used in another STORED PROCEDURE and so on.
I am not sure how to create these stored procedure, because for these stored procedure I need to have temporary tables present in temdb.
Any help
Can you user Global Temporary Tables?
SELECT * INTO ##Users FROM UserTable
The Global temp tables will remain in tempdb until deleted and can be used across different stored procs.
Assuming you want to name the table (or some of its columns) that's about to be created based on the data present in the temp table, you might want to resort to dynamic SQL, since you can't use variables like this:
declare @foo varchar(50)
select @foo = tableName from #tempTable
create table @foo (fooColumn int)
But before you even think of using dynamic SQL, you've got to ask yourself whether you really need this solution.
精彩评论