April 20, 2010 at 9:56 am
Hi,
I'm following some tutortials at the moment that ask me to create @table variables. I find that I have to run the entire script over and over again to get my results as the table variable is only alive when running the scripts.
Is there an enviroment or session variable I can set that will keep the variable alive during my session without having to include in my script every time?
Any help welcome on this.
thanks,
EamonOD:-)
April 20, 2010 at 10:32 am
No, this is the way that table variables are supposed to work.
What you can do is change all of the "DECLARE @TABLE TABLE" statements to "CREATE TABLE #TABLE", then change @TABLE to #TABLE everywhere in your code. It will then persist until explicitly dropped, or the connection is closed.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 20, 2010 at 10:46 am
Or plan B if you'd rather not wait... just add this where you need to debug
SELECT * FROM #tmp from @table
April 21, 2010 at 2:14 am
Thanks alot guys this is what I thought but decided to post this question just in case I missed some new feature addition to SQL server.
Thanks for the help on this.
EamonOD
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply