<?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: Multiple &amp;quot;select&amp;quot; statements using 1 db connection? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-quot-select-quot-statements-using-1-db-connection/m-p/736306#M229349</link>
    <description>&lt;P&gt;You just want to print the results into the output window? You don't want to store them somewhere?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either run each query separately.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT * FROM CONNECTION TO DB2(
  SELECT MAX(DT_LST_UPDT) AS CD_EVNT_ONE_DT_LST_UPDT FROM DB2PROD.CD_EVNT_ONE
);
SELECT * FROM CONNECTION TO DB2(
  SELECT MAX(DT_LST_UPDT) AS CD_EVNT_TWO_DT_LST_UPDT FROM DB2PROD.CD_EVNT_TWO
);
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or tell the remote DB you want it run ONE query that returns all of the results: (Note every implementation of SQL has its own quirks so syntax might need some tweaking). In which case you probably need to add a second variable to tell where the&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT * FROM CONNECTION TO DB2(
  SELECT 'DB2PROD.CD_EVNT_ONE' as source,MAX(DT_LST_UPDT) AS DT_LST_UPDT FROM DB2PROD.CD_EVNT_ONE
  union
  SELECT 'DB2PROD.CD_EVNT_TWO' as source,MAX(DT_LST_UPDT) AS DT_LST_UPDT FROM DB2PROD.CD_EVNT_TWO
  ...
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you probably want to make a TABLE and not just print the results.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want as 
SELECT * FROM CONNECTION TO DB2(
  SELECT 'DB2PROD.CD_EVNT_ONE' as source,MAX(DT_LST_UPDT) AS DT_LST_UPDT FROM DB2PROD.CD_EVNT_ONE
  union
  SELECT 'DB2PROD.CD_EVNT_TWO' as source,MAX(DT_LST_UPDT) AS DT_LST_UPDT FROM DB2PROD.CD_EVNT_TWO
  ...
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 22 Apr 2021 02:02:00 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-04-22T02:02:00Z</dc:date>
    <item>
      <title>Multiple "select" statements using 1 db connection?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-quot-select-quot-statements-using-1-db-connection/m-p/736090#M229307</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a newbie and I need to run a query against 400+ tables in a DB2 database to capture the max last update. Is it possible to have multiple "select" statements using 1 DB2 connection?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, how can get the results in a form of a list, for example:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;table1&lt;/TD&gt;&lt;TD&gt;1/1/2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;table2&lt;/TD&gt;&lt;TD&gt;1/2/2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;table3&lt;/TD&gt;&lt;TD&gt;1/3/2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;table4&lt;/TD&gt;&lt;TD&gt;1/4/2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;table5&lt;/TD&gt;&lt;TD&gt;1/5/2021&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the program and when I run it, it only returns the result from the 1st select statement. No errors in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%udb(DB2P)&lt;BR /&gt;SELECT * FROM CONNECTION TO DB2(&lt;BR /&gt;&lt;STRONG&gt;SELECT MAX(DT_LST_UPDT) AS CD_EVNT_ONE_DT_LST_UPDT FROM DB2PROD.CD_EVNT_ONE;&lt;/STRONG&gt;&lt;BR /&gt;SELECT MAX(DT_LST_UPDT) AS CD_EVNT_TWO_DT_LST_UPDT FROM DB2PROD.CD_EVNT_TWO;&lt;BR /&gt;SELECT MAX(DT_LST_UPDT) AS CD_EVNT_THREE_DT_LST_UPDT FROM DB2PROD.CD_EVNT_THREE;&lt;BR /&gt;SELECT MAX(DT_LST_UPDT) AS CD_EVNT_FOUR_DT_LST_UPDT FROM DB2PROD.CD_EVNT_FOUR;&lt;BR /&gt;SELECT MAX(DT_LST_UPDT) AS CD_EVNT_FIVE_DT_LST_UPDT FROM DB2PROD.CD_EVNT_FIVE;&lt;BR /&gt;); quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mary&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 19:33:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-quot-select-quot-statements-using-1-db-connection/m-p/736090#M229307</guid>
      <dc:creator>Mary001</dc:creator>
      <dc:date>2021-04-21T19:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple "select" statements using 1 db connection?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-quot-select-quot-statements-using-1-db-connection/m-p/736269#M229327</link>
      <description>&lt;P&gt;i would create a libname, and not use passthrough here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your query is simple enough that implicit pass-through can be used with no adverse effect.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname DB2PROD   ....   ;
proc sql;
SELECT MAX(DT_LST_UPDT) AS CD_EVNT_ONE_DT_LST_UPDT FROM DB2PROD.CD_EVNT_ONE;
SELECT MAX(DT_LST_UPDT) AS CD_EVNT_TWO_DT_LST_UPDT FROM DB2PROD.CD_EVNT_TWO;
SELECT MAX(DT_LST_UPDT) AS CD_EVNT_THREE_DT_LST_UPDT FROM DB2PROD.CD_EVNT_THREE;
SELECT MAX(DT_LST_UPDT) AS CD_EVNT_FOUR_DT_LST_UPDT FROM DB2PROD.CD_EVNT_FOUR;
SELECT MAX(DT_LST_UPDT) AS CD_EVNT_FIVE_DT_LST_UPDT FROM DB2PROD.CD_EVNT_FIVE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Apr 2021 21:56:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-quot-select-quot-statements-using-1-db-connection/m-p/736269#M229327</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-21T21:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple "select" statements using 1 db connection?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-quot-select-quot-statements-using-1-db-connection/m-p/736306#M229349</link>
      <description>&lt;P&gt;You just want to print the results into the output window? You don't want to store them somewhere?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either run each query separately.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT * FROM CONNECTION TO DB2(
  SELECT MAX(DT_LST_UPDT) AS CD_EVNT_ONE_DT_LST_UPDT FROM DB2PROD.CD_EVNT_ONE
);
SELECT * FROM CONNECTION TO DB2(
  SELECT MAX(DT_LST_UPDT) AS CD_EVNT_TWO_DT_LST_UPDT FROM DB2PROD.CD_EVNT_TWO
);
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or tell the remote DB you want it run ONE query that returns all of the results: (Note every implementation of SQL has its own quirks so syntax might need some tweaking). In which case you probably need to add a second variable to tell where the&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT * FROM CONNECTION TO DB2(
  SELECT 'DB2PROD.CD_EVNT_ONE' as source,MAX(DT_LST_UPDT) AS DT_LST_UPDT FROM DB2PROD.CD_EVNT_ONE
  union
  SELECT 'DB2PROD.CD_EVNT_TWO' as source,MAX(DT_LST_UPDT) AS DT_LST_UPDT FROM DB2PROD.CD_EVNT_TWO
  ...
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you probably want to make a TABLE and not just print the results.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want as 
SELECT * FROM CONNECTION TO DB2(
  SELECT 'DB2PROD.CD_EVNT_ONE' as source,MAX(DT_LST_UPDT) AS DT_LST_UPDT FROM DB2PROD.CD_EVNT_ONE
  union
  SELECT 'DB2PROD.CD_EVNT_TWO' as source,MAX(DT_LST_UPDT) AS DT_LST_UPDT FROM DB2PROD.CD_EVNT_TWO
  ...
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Apr 2021 02:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-quot-select-quot-statements-using-1-db-connection/m-p/736306#M229349</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-22T02:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple "select" statements using 1 db connection?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-quot-select-quot-statements-using-1-db-connection/m-p/736470#M229425</link>
      <description>&lt;P&gt;THANK YOU SO MUCH, Tom and Chris!!! You guys are a lifesaver!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 17:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-quot-select-quot-statements-using-1-db-connection/m-p/736470#M229425</guid>
      <dc:creator>Mary001</dc:creator>
      <dc:date>2021-04-22T17:16:46Z</dc:date>
    </item>
  </channel>
</rss>

