<?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: joining 2 oracle tables in pass through in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/615027#M179853</link>
    <description>&lt;P&gt;Not tested but based on the code you've posted something like below could work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CONNECT TO ORACLE (USER=&amp;amp;NAME  PW=&amp;amp;PASS  PATH=EX);
  CREATE TABLE ICO AS
    SELECT *
    FROM CONNECTION TO ORACLE
    (
      SELECT 
        a.BAN,
        a.INDICATOR,
        a.BL_IND,
        b.SUB_NO,
        b.SUB_STATUS,
        b.PRODUCT_TYPE
      FROM  
        ODS.BILLING_ACCOUNT a
        left join
        ODS.SUB b
      ON 
        a.BAN = b.CUSTOMER_ID
      WHERE 
        a.STATUS IN ('O','S') 
        AND a.ACCOUNT_TYPE='I'
        AND a.ACCOUNT_SUB_TYPE = 'R'
        and b.SUB_STATUS =  'A'
    )
    ;
  DISCONNECT FROM ORACLE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Try to avoid any sort of functions in join conditions/where clauses as then the database won't be able to use indexes if there are any.&lt;/P&gt;
&lt;PRE&gt;AND ACCOUNT_TYPE||ACCOUNT_SUB_TYPE = 'IR'&lt;/PRE&gt;
&lt;P&gt;I've also formulated the whole SQL without the inline views for the same reason - to give Oracle a better "chance" to use indexes and optimize the query. The Oracel SQL optimizer is pretty good so not sure if it will make a difference (if you've got Toad/SQL Developer then you could execute an EXPLAIN on the code to see what Oracle does with it).&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jan 2020 18:57:38 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-01-03T18:57:38Z</dc:date>
    <item>
      <title>joining 2 oracle tables in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/614988#M179833</link>
      <description>&lt;P&gt;hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to join 2 oracle tables using pass through but i keep mucking up the syntax... this is what i have . What I am doing wrong ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;PROC SQL;&lt;BR /&gt;&amp;nbsp;CONNECT TO ORACLE (USER=&amp;amp;NAME&amp;nbsp; PW=&amp;amp;PASS&amp;nbsp; PATH=EX);&lt;BR /&gt;&amp;nbsp;CREATE TABLE ICO AS&lt;BR /&gt;&amp;nbsp;&amp;nbsp;SELECT A.*,B.* FROM CONNECTION TO ORACLE&lt;BR /&gt;&amp;nbsp;&amp;nbsp;(SELECT BAN,INDICATOR,BL_IND&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM&amp;nbsp; ODS.BILLING_ACCOUNT&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE STATUS IN ('O','S') AND ACCOUNT_TYPE||ACCOUNT_SUB_TYPE = 'IR')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&lt;BR /&gt;&amp;nbsp;&amp;nbsp;LEFT JOIN&lt;BR /&gt;&amp;nbsp;&amp;nbsp;(SELECT SUB_NO,SUB_STATUS,PRODUCT_TYPE&lt;BR /&gt;&amp;nbsp;&amp;nbsp;FROM ODS.SUB B&lt;BR /&gt;&amp;nbsp;&amp;nbsp;WHERE SUB_STATUS =&amp;nbsp; 'A' &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ON A.BAN = B.CUSTOMER_ID&lt;BR /&gt;&amp;nbsp;;&lt;BR /&gt;&amp;nbsp;DISCONNECT FROM ORACLE;&lt;BR /&gt;QUIT;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 15:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/614988#M179833</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-01-03T15:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: joining 2 oracle tables in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/615027#M179853</link>
      <description>&lt;P&gt;Not tested but based on the code you've posted something like below could work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CONNECT TO ORACLE (USER=&amp;amp;NAME  PW=&amp;amp;PASS  PATH=EX);
  CREATE TABLE ICO AS
    SELECT *
    FROM CONNECTION TO ORACLE
    (
      SELECT 
        a.BAN,
        a.INDICATOR,
        a.BL_IND,
        b.SUB_NO,
        b.SUB_STATUS,
        b.PRODUCT_TYPE
      FROM  
        ODS.BILLING_ACCOUNT a
        left join
        ODS.SUB b
      ON 
        a.BAN = b.CUSTOMER_ID
      WHERE 
        a.STATUS IN ('O','S') 
        AND a.ACCOUNT_TYPE='I'
        AND a.ACCOUNT_SUB_TYPE = 'R'
        and b.SUB_STATUS =  'A'
    )
    ;
  DISCONNECT FROM ORACLE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Try to avoid any sort of functions in join conditions/where clauses as then the database won't be able to use indexes if there are any.&lt;/P&gt;
&lt;PRE&gt;AND ACCOUNT_TYPE||ACCOUNT_SUB_TYPE = 'IR'&lt;/PRE&gt;
&lt;P&gt;I've also formulated the whole SQL without the inline views for the same reason - to give Oracle a better "chance" to use indexes and optimize the query. The Oracel SQL optimizer is pretty good so not sure if it will make a difference (if you've got Toad/SQL Developer then you could execute an EXPLAIN on the code to see what Oracle does with it).&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 18:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/615027#M179853</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-01-03T18:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: joining 2 oracle tables in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/615028#M179854</link>
      <description>&lt;P&gt;On the SAS side there is no A and B alias. Just the single source of CONNECTION TO ORACLE.&amp;nbsp; So if need to use SELECT A.*, B.* that needs to part of query you are sending to Oracle.&amp;nbsp; If you have some other tool for connecting to Oracle, such as TOAD, you can test your pass thru code there first and then past it into the SAS code between the parentheses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like to place closing parenthesis under the opening parenthesis to make this easier to see (like placing the END under the DO in a block).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CREATE TABLE ICO AS
  SELECT * FROM CONNECTION TO ORACLE
  ( select a.*,b.* 
     from 
     (SELECT BAN,INDICATOR,BL_IND
      FROM  ODS.BILLING_ACCOUNT
      WHERE STATUS IN ('O','S') AND ACCOUNT_TYPE||ACCOUNT_SUB_TYPE = 'IR')
     ) A
    LEFT JOIN
     (SELECT SUB_NO,SUB_STATUS,PRODUCT_TYPE
      FROM ODS.SUB 
      WHERE SUB_STATUS =  'A'
     ) B 
   ON A.BAN = B.CUSTOMER_ID
  )
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 18:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/615028#M179854</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-03T18:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: joining 2 oracle tables in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/615755#M180144</link>
      <description>&lt;P&gt;Thanks&amp;nbsp; for the explanation! it worked!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 19:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/615755#M180144</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-01-07T19:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: joining 2 oracle tables in pass through</title>
      <link>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/615757#M180145</link>
      <description>Thank you so much. This worked as well. I am usually just pulling variable using pass through and then joining. this is more efficient and seems faster.</description>
      <pubDate>Tue, 07 Jan 2020 19:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/joining-2-oracle-tables-in-pass-through/m-p/615757#M180145</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-01-07T19:03:23Z</dc:date>
    </item>
  </channel>
</rss>

