<?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: max date in create table in sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797941#M313730</link>
    <description>&lt;UL&gt;
&lt;LI&gt;Please post the complete log from that step into a window opened with this button:&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/LI&gt;
&lt;LI&gt;Since this happens in explicit pass-through, you should consult sources that deal with that specific DBMS&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Wed, 23 Feb 2022 06:08:20 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-02-23T06:08:20Z</dc:date>
    <item>
      <title>max date in create table in sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797932#M313729</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi Instructors,&lt;/P&gt;
&lt;P&gt;I created table as below:&lt;/P&gt;
&lt;PRE&gt;create table WORK.RelationTable as select * from connection to ServerName
(select distinct A.*
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,INDV_KEY
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,TO_KEY
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,RLTN_TX
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,RLTN_STRT_DT
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,max(RLTN_END_DT) as RLTN_END_DT from &amp;amp;TableSourceOne. A
INNER join ##TableSourceTwo B
on (A.INDV_KEY=B.TO_INDV_KEY)
);&lt;/PRE&gt;
&lt;P&gt;the error occurs at&amp;nbsp;&lt;STRONG&gt;max(RLTN_END_DT) as RLTN_END_DT, &lt;/STRONG&gt;when I change back to&amp;nbsp;&lt;STRONG&gt;RLTN_END_DT,&lt;/STRONG&gt; then it runs ok.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried add a filter &lt;STRONG&gt;where&amp;nbsp;&amp;nbsp;RLTN_END_DT=max(RLTN_END_DT), &lt;/STRONG&gt;it doesn't work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What shoud I do?&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;RLTN_END_DT: relation end datetime&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 04:15:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797932#M313729</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-02-23T04:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: max date in create table in sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797941#M313730</link>
      <description>&lt;UL&gt;
&lt;LI&gt;Please post the complete log from that step into a window opened with this button:&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/LI&gt;
&lt;LI&gt;Since this happens in explicit pass-through, you should consult sources that deal with that specific DBMS&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 23 Feb 2022 06:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797941#M313730</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-23T06:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: max date in create table in sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797942#M313731</link>
      <description>&lt;P&gt;1. Is &lt;STRONG&gt;max&lt;/STRONG&gt; a valid function name in your database?&lt;/P&gt;
&lt;P&gt;2. Do you really want to use &lt;STRONG&gt;max()&lt;/STRONG&gt; and have no&lt;STRONG&gt; group by&lt;/STRONG&gt; clause?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 06:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797942#M313731</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-02-23T06:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: max date in create table in sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797950#M313738</link>
      <description>&lt;P&gt;I added group by clause&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table WORK.RELATION as select * from connection to SQLSERVER
		    (select distinct A.*, INDV_KEY, TO_INDV_KEY, RLTN_TX, RLTN_STRT_DT, MAX(RLTN_END_DT) as RLTN_END_DT from &amp;amp;TABLENAMEONE. A
				INNER join ##TABLEDATATWO B
					on (A.INDV_KEY=B.TO_INDV_KEY)				
			)GROUP BY INDV_KEY;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ERROR: CLI describe error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Column '&lt;CODE class=" language-sas"&gt;TABLENAMEONE.&lt;/CODE&gt;INDV_KEY' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. : &lt;BR /&gt;[SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]The batch could not be analyzed because of compile errors.&lt;/P&gt;
&lt;P&gt;what is wrong with my "&lt;CODE class=" language-sas"&gt;MAX(RLTN_END_DT)".&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Please help. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 07:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797950#M313738</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-02-23T07:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: max date in create table in sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797953#M313740</link>
      <description>&lt;P&gt;The message couldn't be clearer:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; Column '&lt;/SPAN&gt;&lt;CODE class="  language-sas"&gt;TABLENAMEONE&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;SPAN&gt;INDV_KEY' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; what is wrong with my "&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function keyword"&gt;MAX&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;RLTN_END_DT&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;"&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/EM&gt;&lt;CODE class="  language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Nothing. As the message mentions, the issue is with&amp;nbsp;&lt;SPAN&gt;INDV_KEY&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What result do you expect from this query? What total time do you expect ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also adding &lt;STRONG&gt;group by&lt;/STRONG&gt; outside of the parentheses makes no sense.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 08:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797953#M313740</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-02-23T08:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: max date in create table in sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797957#M313742</link>
      <description>&lt;P&gt;In previous code which run correct and get the table below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="561"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="132"&gt;INDV_KEY&lt;/TD&gt;
&lt;TD width="113"&gt;TO_INDV_KEY&lt;/TD&gt;
&lt;TD width="85"&gt;RLTN_TX&lt;/TD&gt;
&lt;TD width="113"&gt;RLTN_STRT_DT&lt;/TD&gt;
&lt;TD width="118"&gt;RLTN_END_DT&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1F6A57115A&lt;/TD&gt;
&lt;TD&gt;1F6A57115B&lt;/TD&gt;
&lt;TD&gt;member&lt;/TD&gt;
&lt;TD&gt;14-Feb-18&lt;/TD&gt;
&lt;TD&gt;30-Apr-18&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1F6A57115A&lt;/TD&gt;
&lt;TD&gt;1F6A57115B&lt;/TD&gt;
&lt;TD&gt;member&lt;/TD&gt;
&lt;TD&gt;24-Feb-18&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I only want the first row to be returned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 08:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797957#M313742</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-02-23T08:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: max date in create table in sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797960#M313744</link>
      <description>&lt;P&gt;First of all, you must tell SQL from where each individual column has to be taken, so all of your column names should either have an A. or B. as prefix. Even if the procedure does not complain (because a certain column is contained in only one table), working without prefixes is sloppy programming.&lt;/P&gt;
&lt;P&gt;Finding a single record in a group is done like this in SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select a.*
from table a
group by a.indv_key
having rltn_end_dt = max(a.rltn_end_dt)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Feb 2022 08:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797960#M313744</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-23T08:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: max date in create table in sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797962#M313745</link>
      <description>Thank you! The code was fixed. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt; Thank you very much!</description>
      <pubDate>Wed, 23 Feb 2022 08:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/max-date-in-create-table-in-sql/m-p/797962#M313745</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-02-23T08:52:25Z</dc:date>
    </item>
  </channel>
</rss>

