|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:05 PM
Points: 1,101,
Visits: 1,193
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 7:47 AM
Points: 1,400,
Visits: 6,886
|
|
That explanation requires expanding slightly, because there is more than one type of temporary table. Local temporary tables (prefixes with '#') go out of scope when the exec command completes. However, use '##' to create a Global temporary table and the table can be accessed outside of the exec statement that created it.
BrainDonor Linkedin
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: 2 days ago @ 1:49 AM
Points: 3,123,
Visits: 4,310
|
|
Good back-to-basics question, thanks Honza.
____________________________________________ Space, the final frontier? not any more... All limits henceforth are self-imposed. “libera tute vulgaris ex”
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: 2 days ago @ 5:49 AM
Points: 691,
Visits: 1,018
|
|
My gut instinct on this was right. Unfortunately I did not listen to this and chose incorrectly. Doh!!
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Monday, May 13, 2013 9:07 AM
Points: 3,046,
Visits: 1,300
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 8:31 AM
Points: 1,146,
Visits: 1,448
|
|
BrainDonor (7/6/2012) That explanation requires expanding slightly, because there is more than one type of temporary table. Local temporary tables (prefixes with '#') go out of scope when the exec command completes. However, use '##' to create a Global temporary table and the table can be accessed outside of the exec statement that created it.
Thanks for the amplification.
And thanks to OP for the interesting question.
Please don't go. The drones need you. They look up to you.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 2:52 PM
Points: 1,350,
Visits: 870
|
|
Great question and a nice way to end the week.
Oh no, we're toast! I've got this. *Keyboard clatter* Woah, how'd you do that? I'm a DBA...Booyah
Yeah, uh huh, you know what it is. Everything I do, I do it big

|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: 2 days ago @ 7:27 AM
Points: 3,547,
Visits: 920
|
|
| This question made up for yesterday's beating. Glad we ending the week with this one.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 4:11 PM
Points: 3,390,
Visits: 3,403
|
|
David Harder (7/6/2012) This question made up for yesterday's beating. Glad we ending the week with this one. Yes, I agree.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 9:02 PM
Points: 5,100,
Visits: 20,195
|
|
Emphasis (bolding) added by this poster
BrainDonor (7/6/2012) That explanation requires expanding slightly, because there is more than one type of temporary table. Local temporary tables (prefixes with '#') go out of scope when the exec command completes. However, use '##' to create a Global temporary table and the table can be accessed outside of the exec statement that created it.
At the completion of the command given in the QOD
exec ('create table #qotd2 (id int))' follows the above since the exec command completes, that is #qotd2 has gone out of scope.
To illustrate, the code below has been modified so that the entire sequence of commands is contained within the scope of the exec command.
exec ('create table #qotd2 (id int) alter table #qotd2 add i int insert into #qotd2 (i) values (2) select * from #qotd2 drop table #qotd2') The above then will return for the SELECT statement the values:
id i NULL 2
If everything seems to be going well, you have obviously overlooked something.
Ron
Please help us, help you -before posting a question please read Before posting a performance problem please read
|
|
|
|