<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating temp table in sql server pass through? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89459#M257216</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure about using ODBC, but with other SAS/Access products you can keep the temporary tables by keeping your connection to the server open using a LIBNAME.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LIBNAME xxx odbc ..... ;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;/P&gt;&lt;P&gt;connect to odbc .... ;&lt;/P&gt;&lt;P&gt;execute ( ... ) by odbc ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 04 Jan 2014 17:03:26 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2014-01-04T17:03:26Z</dc:date>
    <item>
      <title>Creating temp table in sql server pass through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89454#M257211</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all. Does anyone happen to know if it's possible to create a temporary table within a sql server pass through. Aka, is there a way to make the following code work?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;connect to odbc as myodbc (dsn=odbc_MYODBC_yay);&lt;/P&gt;&lt;P&gt;create table finalresults as&lt;/P&gt;&lt;P&gt;select * from connection to myodbc&lt;/P&gt;&lt;P&gt;(select *&lt;/P&gt;&lt;P&gt;into #temporaryTable&lt;/P&gt;&lt;P&gt;from mastertable&lt;/P&gt;&lt;P&gt;where mycolumn='0001'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from #temporarytable);&lt;/P&gt;&lt;P&gt;disconnect from myodbc;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Obviously this is a simplified version of the code I would like to write, however if possible it would results in much easier code to maintain, transfer, and a general efficency gain.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I should pre-face this with the note that I know a workaround for this. It's simple to create a stored procedure to do everything you need, and then pull from the table created within the stored procedure, and then drop the table (or a few other work arounds I've used before).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SO I don't need a solution to the problem per-say, I just need to know if this exact solution is someway possible!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;Thanks so much!&lt;/P&gt;&lt;P&gt;Brandon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2013 22:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89454#M257211</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-05-29T22:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating temp table in sql server pass through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89455#M257212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, no problem. Check out the EXECUTE statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;connect to odbc as myodbc (dsn=odbc_MYODBC_yay);&lt;/P&gt;&lt;P&gt;execute(create table #temporaryTable as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select from mastertable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where mycolumn='0001') by myodbc;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can run any SQL Server-specific statements this way, even stored procedures.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 May 2013 01:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89455#M257212</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2013-05-30T01:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating temp table in sql server pass through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89456#M257213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;So I have a few issues with doing things this way. The first is, if I define a temporary table with two ## (a global temporary table) I cannot then go into sql server and open this temporary table (or create a second sql server pass through functionality to pull data from the intermediate temporary table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I actually need to create 3-4 temporary tables, and then pull the final results into a SAS dataset, where that result is simply the select from the last temporary table created.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Brandon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 May 2013 13:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89456#M257213</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-05-30T13:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating temp table in sql server pass through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89457#M257214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Brandon, &lt;/P&gt;&lt;P&gt;Did you ever receive a reply or figure out how to do this?&amp;nbsp; I have a need to do something similar.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;"I actually need to create 3-4 temporary tables, and then pull the final results into a SAS dataset, where that result is simply the select from the last temporary table created."&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jan 2014 14:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89457#M257214</guid>
      <dc:creator>alandool</dc:creator>
      <dc:date>2014-01-03T14:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating temp table in sql server pass through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89458#M257215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did alandool. It appears that if you make independent execute queries as SASKiwi does above this can be done. Just make x different queries, 1 for each temp table plus 1 additional to pull it into the sas system!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jan 2014 15:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89458#M257215</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2014-01-03T15:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating temp table in sql server pass through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89459#M257216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure about using ODBC, but with other SAS/Access products you can keep the temporary tables by keeping your connection to the server open using a LIBNAME.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LIBNAME xxx odbc ..... ;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;/P&gt;&lt;P&gt;connect to odbc .... ;&lt;/P&gt;&lt;P&gt;execute ( ... ) by odbc ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Jan 2014 17:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89459#M257216</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-01-04T17:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating temp table in sql server pass through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89460#M257217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why would you try to outsmart a SQL optimizer either at the SAS site or at the DBMS site?&lt;/P&gt;&lt;P&gt;SQL is using temporary tables when it decides they are needed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jan 2014 09:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89460#M257217</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-01-05T09:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating temp table in sql server pass through?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89461#M257218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Anotherdream and Tom!&amp;nbsp;&amp;nbsp; I was able to do what was needed by enclosing sql statements as mentioned:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;exec(&amp;nbsp; ......&amp;nbsp;&amp;nbsp; ) by sqlsvr;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jan 2014 18:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-temp-table-in-sql-server-pass-through/m-p/89461#M257218</guid>
      <dc:creator>alandool</dc:creator>
      <dc:date>2014-01-05T18:00:28Z</dc:date>
    </item>
  </channel>
</rss>

