Click here to Skip to main content
15,887,585 members
Articles / Database Development / SQL Server
Alternative
Tip/Trick

Updating a temp table in a Stored Proc

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
1 Nov 2011CPOL 6.4K   1
You might also want to try using a table variable - like this:DECLARE @tableName TABLE ( Key1 INT, Key2 INT, Description NVARCHAR(255), AggAmount FLOAT,)Then you can refer to your table by @tableName. Granted this is SQL Server 2005 and above, but then...

You might also want to try using a table variable - like this:


SQL
DECLARE @tableName TABLE  ( 
    Key1        INT,
    Key2        INT,
    Description NVARCHAR(255),
    AggAmount   FLOAT,
)

Then you can refer to your table by @tableName. Granted this is SQL Server 2005 and above, but then you don't have to worry about making sure your temp table exists or is not in tempdb.


The other option is, if it is a temp table, just delete it at the end of your Stored Procedure so it doesn't exist in tempdb anymore and release resources to SQL Server. Then if you change the schema in the beginning of your procedure, it doesn't matter.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 4 Reason I'm using a temp table in the... Pin
Mel Padden1-Nov-11 6:48
Mel Padden1-Nov-11 6:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.