<?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: Connect to SQL Server to update temporary dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/689074#M209449</link>
    <description>This doesn't work out for me as my dataset 'tt' is a temporary dataset in SAS. I'm trying to update it using joins with tables from SQL server.</description>
    <pubDate>Tue, 06 Oct 2020 03:40:53 GMT</pubDate>
    <dc:creator>Ja5ya</dc:creator>
    <dc:date>2020-10-06T03:40:53Z</dc:date>
    <item>
      <title>Connect to SQL Server to update temporary dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/688864#M209360</link>
      <description>&lt;DIV&gt;I am trying to update a variable in my temporary dataset named 'tt' by joining it to a database in sql server. But I am getting the following error:&amp;nbsp;&lt;STRONG&gt;[SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Invalid object name '##tt'.&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Below is the code I used:&lt;/DIV&gt;&lt;DIV&gt;proc sql;&lt;/DIV&gt;&lt;DIV&gt;connect to sqlsvr as oledb (datasrc="&amp;amp;server_name" user="&amp;amp;sasusr" password="&amp;amp;saspwd");&lt;/DIV&gt;&lt;DIV&gt;execute (&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;Update a&lt;/DIV&gt;&lt;DIV&gt;Set Network = PNSN.network_id&lt;/DIV&gt;&lt;DIV&gt;From ##tt as a&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; JOIN &amp;amp;database..dbo.Network_Names as PNSN&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; ON PNSN.network_gid = PS.network_gid&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; AND PNSN.status = 'w'&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; WHERE a.Network IS NULL&lt;/DIV&gt;&lt;DIV&gt;) by oledb;&lt;/DIV&gt;&lt;DIV&gt;disconnect from oledb;&lt;/DIV&gt;&lt;DIV&gt;quit;&lt;/DIV&gt;&lt;DIV&gt;Please help.&lt;/DIV&gt;</description>
      <pubDate>Mon, 05 Oct 2020 12:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/688864#M209360</guid>
      <dc:creator>Ja5ya</dc:creator>
      <dc:date>2020-10-05T12:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL Server to update temporary dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/688888#M209367</link>
      <description>&lt;P&gt;In testing, I have found that once you disconnect from MSSQL Server, temp tables are deleted by MS SQL Server.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to odbc as oledb (datasrc="mssql-orion" user=orion password=Metadata0 ) ;
execute(
IF object_id('tempdb..##test') is not null
BEGIN
DROP TABLE ##test
END
create table orion.##test 
(id int, name varchar(12)))by oledb;
execute(insert into orion.##test(ID,Name) values(1,'Mark')) by oledb ;
execute(insert into orion.##test(ID,Name) values(2,'Joe')) by oledb ;
select * from connection to oledb (select * from orion.##test);
disconnect from oledb ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This produces the results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;id&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;name&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;Mark&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;Joe&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you check in&amp;nbsp;Microsoft SQL Server Management Studio (MSSMS) the table &lt;STRONG&gt;##test&lt;/STRONG&gt; no longer exists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this submitting just this in interactive mode:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to odbc as oledb (datasrc="mssql-orion" user=orion password=Metadata0 ) ;
execute(
IF object_id('tempdb..##test') is not null
BEGIN
   DROP TABLE ##test
END
create table orion.##test 
(id int, name varchar(12)))by oledb;
execute(insert into orion.##test(ID,Name) values(1,'Mark')) by oledb ;
execute(insert into orion.##test(ID,Name) values(2,'Joe'))  by oledb ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And as long as PROC SQL remained running, I could see the temp table &lt;STRONG&gt;##test&lt;/STRONG&gt; in MSSMS. As soon as I executed the DISCONNECT statement in SAS, table &lt;STRONG&gt;##test&lt;/STRONG&gt; disappeared from MSSMS, too.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this directly in&amp;nbsp;MSSMS (without using SAS). The table remained available in&amp;nbsp;MSSMS until I shut down the program. Upon logging back in, table &lt;STRONG&gt;##test&lt;/STRONG&gt; was no longer available.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It then appears to me that this is normal behavior for MS SQL Server temp tables. Consider completing all the required work with the temp table before disconnecting from MS SQL Server, or using a normal table to do your work and explicitly then deleting it when finished.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 14:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/688888#M209367</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2020-10-05T14:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL Server to update temporary dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/689074#M209449</link>
      <description>This doesn't work out for me as my dataset 'tt' is a temporary dataset in SAS. I'm trying to update it using joins with tables from SQL server.</description>
      <pubDate>Tue, 06 Oct 2020 03:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/689074#M209449</guid>
      <dc:creator>Ja5ya</dc:creator>
      <dc:date>2020-10-06T03:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL Server to update temporary dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/689314#M209529</link>
      <description>&lt;P&gt;The code you posted updates a temporary table in SQL Server but you are now saying it is a SAS WORK table? Where do you want the end result? A table in SAS or in SQL Server?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 19:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/689314#M209529</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-10-06T19:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL Server to update temporary dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/689349#M209545</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349550"&gt;@Ja5ya&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;This doesn't work out for me as my dataset 'tt' is a temporary dataset in SAS. I'm trying to update it using joins with tables from SQL server.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The code you posted is a pure pass-through to SQL Server. It does NOTHING with SAS datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As the term implies,&amp;nbsp;&lt;EM&gt;temporary&lt;/EM&gt; tables exist only for the duration of a connection.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 21:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/689349#M209545</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-06T21:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL Server to update temporary dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/689968#M209812</link>
      <description>&lt;P&gt;The code you supplied doesn't make any SAS tables at all - the ##test table is an SQL Server temp table. You could add CREATE TABLE WORK.TEST AS just before the final SELECT statement to create a SAS work library table before disconnecting from SQL server to copy the data from SQL Server into the SAS work library. Something like this should do it:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to odbc as oledb (datasrc="mssql-orion" user=orion password=Metadata0 ) ;
execute(
IF object_id('tempdb..##test') is not null
BEGIN
DROP TABLE ##test
END
create table orion.##test 
(id int, name varchar(12)))by oledb;
execute(insert into orion.##test(ID,Name) values(1,'Mark')) by oledb ;
execute(insert into orion.##test(ID,Name) values(2,'Joe')) by oledb ;

create table WORK.TEST as 
select * from connection to oledb (select * from orion.##test);
disconnect from oledb ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Oct 2020 13:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/689968#M209812</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2020-10-08T13:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL Server to update temporary dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/690267#M209993</link>
      <description>Thanks!</description>
      <pubDate>Fri, 09 Oct 2020 04:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Connect-to-SQL-Server-to-update-temporary-dataset/m-p/690267#M209993</guid>
      <dc:creator>Ja5ya</dc:creator>
      <dc:date>2020-10-09T04:54:09Z</dc:date>
    </item>
  </channel>
</rss>

