October 7, 2010 at 4:54 am
I am inserting into temprary table using INTO statement by execute sqlstring.
e.g
Declare @sqlstring as nvarchar(max)
set @sqlstring =" Select column1,column2 INTO #temptable From TableName"
executesql @sqlstring
Select * from #temptable
but it gives be error .....#temptable is undefined.
What is the problem??
Please help its urgent.......................
October 7, 2010 at 5:01 am
it's scope; the table exists INSIDE the exec statement, but is destroyed when it comes back to the "outer" scope of code that called the EXEC..
you have to create the temp table before using the exec statement;
CREATE TABLE #temptable(Column1 varchar(30), etc....)
set @sqlstring =" INSERT INTO #temptable Select column1,column2 From TableName"
executesql @sqlstring
i assume this is an example, as nothing you really posted needs to be done with dynamic SQL;
Lowell
October 7, 2010 at 9:54 pm
Hey Lowell... congrats on the 5K mark. You're one of those that works for every single post and your 5K mark is like a 10K mark for others on other forums. Well done ol' friend.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 7, 2010 at 10:43 pm
thanks lowell
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply