<?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: Temporary tables on sql server in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593480#M170312</link>
    <description>Libnames sqltest and sqltest1 have different schemas.&lt;BR /&gt;I tried doing this too after deleting the 2nd libname:&lt;BR /&gt;From ##Table1 a1&lt;BR /&gt;inner join schema2.Table2 a&lt;BR /&gt;on a1.ID=a.ID&lt;BR /&gt;&lt;BR /&gt;This gives me this error:&lt;BR /&gt;ERROR: CLI describe error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Invalid column name 'ID'. :&lt;BR /&gt;[SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]The batch could not be analyzed because of compile errors.</description>
    <pubDate>Wed, 02 Oct 2019 17:26:26 GMT</pubDate>
    <dc:creator>AJ_Brien</dc:creator>
    <dc:date>2019-10-02T17:26:26Z</dc:date>
    <item>
      <title>Temporary tables on sql server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593459#M170305</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to create a temporary table on sql server and move my work dataset there. However, when I join that with another sql server table, I get this error:&lt;/P&gt;&lt;P&gt;ERROR: CLI describe error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Invalid object name&lt;BR /&gt;'sqltest1.Table2'. : [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]The metadata could not be&lt;BR /&gt;determined because every code path results in an error; see previous errors for some of these.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand the purpose of '##' but I read it on a couple of SAS documentation websites so I'm using it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please find code below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME sqltest SQLSVR User="%sysget(USER)" Password="xx" DSN="xx" schema="xx" connection=shared;

proc sql;
     drop table sqltest."##Table1"n;
quit;

proc sql;
     create table sqltest."##Table1"n as 
           select   * from work.hb;
quit;

libname sqltest1 SQLSVR User="%sysget(USER)" Password="xx" DSN="xx" schema="xx" connection=shared;

 
proc sql;
   connect to SQLSVR as FA(User="%sysget(USER)" Password="xx" DSN="xx");
CREATE TABLE abc AS 
SELECT  * FROM connection to fa

(select a1.*, 
a.var1, 
a.var2

From ##Table1 a1
inner join sqltest1.Table2 a
on a1.ID=a.ID

);
DISCONNECT FROM FA;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Logs:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;GOPTIONS ACCESSIBLE;
LIBNAME sqltest SQLSVR User="%sysget(USER)" Password="xx " DSN="xx" schema="xx" connection=shared;
NOTE: Libref SQLTEST was successfully assigned as follows: 
      Engine:        SQLSVR 
      Physical Name: xx
proc sql;
drop table sqltest."##Table1"n;
WARNING: File SQLTEST.'##Table1'n.DATA does not exist.
WARNING: Table SQLTEST.'##Table1'n has not been dropped.
quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.07 seconds
      user cpu time       0.05 seconds
      system cpu time     0.00 seconds
      memory              85.46k
      OS Memory           25764.00k
      Timestamp           10/02/2019 11:16:06 AM
      Step Count                        14  Switch Count  0
      Page Faults                       0
      Page Reclaims                     36
      Page Swaps                        0
2                                                          The SAS System                           09:55 Wednesday, October 2, 2019

      Voluntary Context Switches        47
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           8
      

proc sql;
create table sqltest."##Table1"n as
select   * from work.hb;
NOTE: SAS variable labels, formats, and lengths are not written to DBMS tables.
NOTE: Table SQLTEST.'##Table1'n created, with 19 rows and 3 columns.
quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.04 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              5338.21k
      OS Memory           31144.00k
      Timestamp           10/02/2019 11:16:06 AM
      Step Count                        15  Switch Count  1
      Page Faults                       0
      Page Reclaims                     58
      Page Swaps                        0
      Voluntary Context Switches        37
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           8
      

libname sqltest1 SQLSVR User="%sysget(USER)" Password="xx" DSN="Xx" schema="xx"
! connection=shared;
NOTE: Libref SQLTEST1 was successfully assigned as follows: 
      Engine:        SQLSVR 
      Physical Name: Xx
proc sql;
connect to SQLSVR as FA(User="%sysget(USER)" Password="xx." DSN="Xx");
CREATE TABLE abc AS
SELECT  * FROM connection to fa
 (select a1.*,
a.var1,
   a.var2

From ##Table1 a1
inner join sqltest1.Table2 a
on a1.ID=a.ID
);
ERROR: CLI describe error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Invalid object name 
       'sqltest1.Table2'. : [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]The metadata could not be 
       determined because every code path results in an error; see previous errors for some of these.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
DISCONNECT FROM FA;
NOTE: Statement not executed due to NOEXEC option.
  QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using &lt;STRONG&gt;From sqltest."##Table1"n a1&lt;/STRONG&gt; instead of&amp;nbsp;&lt;STRONG&gt;From ##Table1 a1&lt;/STRONG&gt;, that gave me the same log but with the following error:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR: CLI describe error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Incorrect syntax near&lt;BR /&gt;'##Table1'. : [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]The batch could not be&lt;BR /&gt;analyzed because of compile errors.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 16:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593459#M170305</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-10-02T16:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables on sql server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593465#M170308</link>
      <description>&lt;P&gt;Remove the second libname statement. It could mean that the connection is dropped, causing the temporary table to be deleted.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 16:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593465#M170308</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-02T16:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables on sql server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593466#M170309</link>
      <description>&lt;P&gt;You didn't include the same options on your CONNECT statement as you did on your LIBNAME statement(s).&amp;nbsp; Importantly you didn't include&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;connection&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;shared&lt;/LI-CODE&gt;
&lt;P&gt;You also didn't test whether you could see the temporary table using the second libref.&amp;nbsp; Instead you appear to have tried to use the SAS libref in your SQL Server code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME sqltest SQLSVR User="%sysget(USER)" Password="xx" DSN="xx" schema="xx" connection=shared;
proc sql;
create table sqltest."##Table1"n as 
  select * from work.hb
;
create table using_libref as select * from sqltest."##Table1"n;
connect using sqltest;
CREATE TABLE using_passthru AS 
SELECT  * FROM connection to sqltest
  (select a1.* from ##Table1 a1)
;
CREATE TABLE using_passthru_join AS 
SELECT  * FROM connection to sqltest
  (select a1.var1,b1.var2 from ##Table1 a1
     inner join some_other_sql_server_table b1
     on a1.var1 = b1.var1
   )
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Oct 2019 16:54:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593466#M170309</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-02T16:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables on sql server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593480#M170312</link>
      <description>Libnames sqltest and sqltest1 have different schemas.&lt;BR /&gt;I tried doing this too after deleting the 2nd libname:&lt;BR /&gt;From ##Table1 a1&lt;BR /&gt;inner join schema2.Table2 a&lt;BR /&gt;on a1.ID=a.ID&lt;BR /&gt;&lt;BR /&gt;This gives me this error:&lt;BR /&gt;ERROR: CLI describe error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Invalid column name 'ID'. :&lt;BR /&gt;[SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]The batch could not be analyzed because of compile errors.</description>
      <pubDate>Wed, 02 Oct 2019 17:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593480#M170312</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-10-02T17:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables on sql server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593488#M170315</link>
      <description>Thank you for this.&lt;BR /&gt;&lt;BR /&gt;My sqltest."##Table1"n gets created perfectly.&lt;BR /&gt;table using_libref also gets craeted.&lt;BR /&gt;&lt;BR /&gt;However, TABLE using_passthru_join gives the following: ERROR: The SQLTEST engine cannot be found.&lt;BR /&gt;ERROR: A Connection to the sqltest DBMS is not currently supported, or is not installed at your site.&lt;BR /&gt;&lt;BR /&gt;I guess it is some sql server thing that needs to be installed. I found another code which uses #### instead of ##, that code runs well too, but when I try to replace #### in my code, it continues to give all the same errors that it did for ##. So am not sure wat's going on at the moment with this.</description>
      <pubDate>Wed, 02 Oct 2019 17:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593488#M170315</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-10-02T17:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Temporary tables on sql server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593498#M170321</link>
      <description>Make sure the libref used in the LIBNAME and CONNECT USING statements match the name used in the CONNECTION TO clause.&lt;BR /&gt;</description>
      <pubDate>Wed, 02 Oct 2019 18:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Temporary-tables-on-sql-server/m-p/593498#M170321</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-02T18:16:32Z</dc:date>
    </item>
  </channel>
</rss>

