﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Honza Mensdorff  / Execs and temporary tables / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 18:45:20 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>I got it wrong :(</description><pubDate>Mon, 22 Oct 2012 23:35:22 GMT</pubDate><dc:creator>kalyani.k478</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]L' Eomot Inversé (7/18/2012)[/b][hr]Nice easy question.  But obviously batch 1 works, and batch 2 can't work (because the table is dropped by the exit from exec), and only one of the answers permits that; a different set of answer options could have made it necessary to look and see what the other batches did, which would perhaps have made it a better (although somewhat more tedious) question.[/quote]I preffered symetry over difficulty. Maybe next time.</description><pubDate>Wed, 18 Jul 2012 12:56:35 GMT</pubDate><dc:creator>honza.mf</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Nice easy question.  But obviously batch 1 works, and batch 2 can't work (because the table is dropped by the exit from exec), and only one of the answers permits that; a different set of answer options could have made it necessary to look and see what the other batches did, which would perhaps have made it a better (although somewhat more tedious) question.</description><pubDate>Wed, 18 Jul 2012 10:08:40 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]Mike Palecek (7/18/2012)[/b][hr]Very good question. I write code fairly often and it seems there is more to think about in SQL about scope than many programming languages. Either that or I just think about it more with programming.[/quote]Thank you. That's it.</description><pubDate>Wed, 18 Jul 2012 06:45:01 GMT</pubDate><dc:creator>honza.mf</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Very good question. I write code fairly often and it seems there is more to think about in SQL about scope than many programming languages. Either that or I just think about it more with programming.</description><pubDate>Wed, 18 Jul 2012 06:23:58 GMT</pubDate><dc:creator>Mike Palecek</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Good question, thanks.</description><pubDate>Tue, 10 Jul 2012 07:58:35 GMT</pubDate><dc:creator>Lon-860191</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>unfortunately, i select the wrong one.  :doze:</description><pubDate>Mon, 09 Jul 2012 04:43:18 GMT</pubDate><dc:creator>Danny Ocean</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]David Harder (7/6/2012)[/b][hr]This question made up for yesterday's beating. Glad we ending the week with this one.[/quote]See I missed this on Friday so was still busy chewing some sour grapes!  However, this week's starting out on a high note (despite the miserable British summer!) :cool:</description><pubDate>Mon, 09 Jul 2012 01:36:19 GMT</pubDate><dc:creator>SQLPhil</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Good Question !!!!!!.</description><pubDate>Mon, 09 Jul 2012 01:15:30 GMT</pubDate><dc:creator>baabhu</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Thanks for the question.</description><pubDate>Mon, 09 Jul 2012 00:28:52 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]WayneS (7/6/2012)[/b][hr][quote][b]mtassin (7/6/2012)[/b][hr]Always nice to have an easy one on Friday.... [/quote]I concur... [b]but what is easy for one person isn't for another[/b].[/quote]I'm surprised, there are someone (9% now) who choosed the "Every batch throws an error" answer. Curious.</description><pubDate>Sat, 07 Jul 2012 07:59:54 GMT</pubDate><dc:creator>honza.mf</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]bitbucket-25253 (7/6/2012)[/b][hr]Emphasis (bolding) added by this poster[quote][b]BrainDonor (7/6/2012)[/b][hr]That explanation requires expanding slightly, because there is more than one type of temporary table. [i]Local[/i] [b]temporary tables (prefixes with '#') go out of scope when the exec command completes.[/b] However, use '##' to create a [i]Global[/i] temporary table and the table can be accessed outside of the exec statement that created it.[/quote]At the completion of the command given in the QOD[code="sql"]exec ('create table #qotd2 (id int))'[/code] 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 [b]entire sequence of commands is contained within the scope of the exec command.[/b][code="sql"]exec ('create table #qotd2 (id int)     alter table #qotd2 add i int     insert into #qotd2 (i) values (2)     select * from #qotd2      drop table #qotd2')[/code]The above then will return for the SELECT statement the values:[code="sql"]id         iNULL       2 [/code][/quote]I must agree. It's the case of B#7.</description><pubDate>Sat, 07 Jul 2012 07:57:48 GMT</pubDate><dc:creator>honza.mf</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Thanks to everyone. Sorry, I missed the beggining of this discussion as I was out of civilization (holiday).</description><pubDate>Sat, 07 Jul 2012 07:52:58 GMT</pubDate><dc:creator>honza.mf</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]Michael Poppers (7/6/2012)[/b][hr]Thanks for the question! but the set of possible answers was "too easy": once I saw that B#2 was going to error out while B#3 was not, I didn't look at the subsequent Bs :-).[/quote]Thanks.I wanted to have it uniform.</description><pubDate>Sat, 07 Jul 2012 07:51:16 GMT</pubDate><dc:creator>honza.mf</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]BrainDonor (7/6/2012)[/b][hr]That explanation requires expanding slightly, because there is more than one type of temporary table. [i]Local[/i] temporary tables (prefixes with '#') go out of scope when the exec command completes. However, use '##' to create a [i]Global[/i] temporary table and the table can be accessed outside of the exec statement that created it.[/quote]You are right. But with global temporary table this will be no fun.</description><pubDate>Sat, 07 Jul 2012 07:49:40 GMT</pubDate><dc:creator>honza.mf</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]mtassin (7/6/2012)[/b][hr]Always nice to have an easy one on Friday.... [/quote]I concur... but what is easy for one person isn't for another.</description><pubDate>Fri, 06 Jul 2012 12:50:32 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Thanks for the question! but the set of possible answers was "too easy": once I saw that B#2 was going to error out while B#3 was not, I didn't look at the subsequent Bs :-).</description><pubDate>Fri, 06 Jul 2012 11:50:03 GMT</pubDate><dc:creator>Michael Poppers</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Nice question to end the week on. Thanks!</description><pubDate>Fri, 06 Jul 2012 09:58:19 GMT</pubDate><dc:creator>KWymore</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]SQLRNNR (7/6/2012)[/b][hr][quote][b]mtassin (7/6/2012)[/b][hr]Always nice to have an easy one on Friday.... [/quote]Yes it is.:-D[/quote]Count me in. :-)</description><pubDate>Fri, 06 Jul 2012 09:12:25 GMT</pubDate><dc:creator>Revenant</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Nice question, thanks for the back to basics.Happy weekend, everyone."El" Jerry.</description><pubDate>Fri, 06 Jul 2012 09:08:01 GMT</pubDate><dc:creator>EL Jerry</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]mtassin (7/6/2012)[/b][hr]Always nice to have an easy one on Friday.... [/quote]Yes it is.:-D</description><pubDate>Fri, 06 Jul 2012 09:03:56 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Always nice to have an easy one on Friday.... </description><pubDate>Fri, 06 Jul 2012 08:30:51 GMT</pubDate><dc:creator>mtassin</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Emphasis (bolding) added by this poster[quote][b]BrainDonor (7/6/2012)[/b][hr]That explanation requires expanding slightly, because there is more than one type of temporary table. [i]Local[/i] [b]temporary tables (prefixes with '#') go out of scope when the exec command completes.[/b] However, use '##' to create a [i]Global[/i] temporary table and the table can be accessed outside of the exec statement that created it.[/quote]At the completion of the command given in the QOD[code="sql"]exec ('create table #qotd2 (id int))'[/code] 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 [b]entire sequence of commands is contained within the scope of the exec command.[/b][code="sql"]exec ('create table #qotd2 (id int)     alter table #qotd2 add i int     insert into #qotd2 (i) values (2)     select * from #qotd2      drop table #qotd2')[/code]The above then will return for the SELECT statement the values:[code="sql"]id         iNULL       2 [/code]</description><pubDate>Fri, 06 Jul 2012 08:12:13 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]David Harder (7/6/2012)[/b][hr]This question made up for yesterday's beating. Glad we ending the week with this one.[/quote]Yes, I agree.</description><pubDate>Fri, 06 Jul 2012 07:42:37 GMT</pubDate><dc:creator>Cliff Jones</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>This question made up for yesterday's beating. Glad we ending the week with this one.</description><pubDate>Fri, 06 Jul 2012 07:28:59 GMT</pubDate><dc:creator>David Harder</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Great question and a nice way to end the week. :-)</description><pubDate>Fri, 06 Jul 2012 07:01:49 GMT</pubDate><dc:creator>Dana Medley</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>[quote][b]BrainDonor (7/6/2012)[/b][hr]That explanation requires expanding slightly, because there is more than one type of temporary table. [i]Local[/i] temporary tables (prefixes with '#') go out of scope when the exec command completes. However, use '##' to create a [i]Global[/i] temporary table and the table can be accessed outside of the exec statement that created it.[/quote]Thanks for the amplification.And thanks to OP for the interesting question.</description><pubDate>Fri, 06 Jul 2012 06:00:41 GMT</pubDate><dc:creator>Thomas Abraham</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Good question, thanks.</description><pubDate>Fri, 06 Jul 2012 04:47:40 GMT</pubDate><dc:creator>Duncan Pryde</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>My gut instinct on this was right.  Unfortunately I did not listen to this and chose incorrectly.  Doh!!:hehe:</description><pubDate>Fri, 06 Jul 2012 01:45:22 GMT</pubDate><dc:creator>skanker</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Good back-to-basics question, thanks Honza.</description><pubDate>Fri, 06 Jul 2012 01:28:57 GMT</pubDate><dc:creator>Stewart "Arturius" Campbell</dc:creator></item><item><title>RE: Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>That explanation requires expanding slightly, because there is more than one type of temporary table. [i]Local[/i] temporary tables (prefixes with '#') go out of scope when the exec command completes. However, use '##' to create a [i]Global[/i] temporary table and the table can be accessed outside of the exec statement that created it.</description><pubDate>Fri, 06 Jul 2012 01:11:37 GMT</pubDate><dc:creator>BrainDonor</dc:creator></item><item><title>Execs and temporary tables</title><link>http://www.sqlservercentral.com/Forums/Topic1325827-1711-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/91274/"&gt;Execs and temporary tables&lt;/A&gt;[/B]</description><pubDate>Thu, 05 Jul 2012 21:40:01 GMT</pubDate><dc:creator>honza.mf</dc:creator></item></channel></rss>