<?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 Teradata: Datatype mismatch error when adding subquery to join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Teradata-Datatype-mismatch-error-when-adding-subquery-to-join/m-p/597387#M172117</link>
    <description>&lt;P&gt;I have the following piece of code that works fine as a standalone pull:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
	connect to teradata (authdomain='LDAP_auth' SERVER= teramed1 mode = teradata);
	create table test as 
	select * from connection to teradata (&lt;BR /&gt;                select sub_ed.eci, sub_ed.hh_episode_bgn,count(sub_ed.incurred_dt) as ed_during_ct&lt;BR /&gt;                , min(incurred_dt) as ed_during_dt
		from sudd02a.hh_3_ed sub_ed left join sudd02a.hh_1_episodes sub_ep
		on sub_ed.eci = sub_ep.eci and sub_ed.hh_episode_bgn = sub_ep.hh_episode_bgn
		group by 1,2
		where sub_ed.incurred_dt between sub_ed.hh_episode_bgn and sub_ep.hh_episode_end);
quit;
&lt;/PRE&gt;
&lt;P&gt;However, when I wrap the select statement into a left join as part of a much larger pull from Teradata&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;left join (select sub_ed.eci, sub_ed.hh_episode_bgn
		, count(sub_ed.incurred_dt) as ed_during_ct
		, min(incurred_dt) as ed_during_dt
		from sudd02a.hh_3_ed sub_ed left join sudd02a.hh_1_episodes sub_ep
		on sub_ed.eci = sub_ep.eci and sub_ed.hh_episode_bgn = sub_ep.hh_episode_bgn
		group by 1,2
		where sub_ed.incurred_dt between sub_ed.hh_episode_bgn and sub_ep.hh_episode_end) ed2
on ep.eci=ed2.eci and ep.hh_episode_bgn=ed2.hh_episode_bgn&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Enterprise Guide throws the error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Teradata prepare: Datatype Mismatch in THEN/ELSE expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't figure out what might be causing that error. It's not the ON variables: there's a join just above this one that uses the exact same tables and variables, and it works fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2019 15:18:12 GMT</pubDate>
    <dc:creator>scify</dc:creator>
    <dc:date>2019-10-17T15:18:12Z</dc:date>
    <item>
      <title>Teradata: Datatype mismatch error when adding subquery to join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Teradata-Datatype-mismatch-error-when-adding-subquery-to-join/m-p/597387#M172117</link>
      <description>&lt;P&gt;I have the following piece of code that works fine as a standalone pull:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
	connect to teradata (authdomain='LDAP_auth' SERVER= teramed1 mode = teradata);
	create table test as 
	select * from connection to teradata (&lt;BR /&gt;                select sub_ed.eci, sub_ed.hh_episode_bgn,count(sub_ed.incurred_dt) as ed_during_ct&lt;BR /&gt;                , min(incurred_dt) as ed_during_dt
		from sudd02a.hh_3_ed sub_ed left join sudd02a.hh_1_episodes sub_ep
		on sub_ed.eci = sub_ep.eci and sub_ed.hh_episode_bgn = sub_ep.hh_episode_bgn
		group by 1,2
		where sub_ed.incurred_dt between sub_ed.hh_episode_bgn and sub_ep.hh_episode_end);
quit;
&lt;/PRE&gt;
&lt;P&gt;However, when I wrap the select statement into a left join as part of a much larger pull from Teradata&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;left join (select sub_ed.eci, sub_ed.hh_episode_bgn
		, count(sub_ed.incurred_dt) as ed_during_ct
		, min(incurred_dt) as ed_during_dt
		from sudd02a.hh_3_ed sub_ed left join sudd02a.hh_1_episodes sub_ep
		on sub_ed.eci = sub_ep.eci and sub_ed.hh_episode_bgn = sub_ep.hh_episode_bgn
		group by 1,2
		where sub_ed.incurred_dt between sub_ed.hh_episode_bgn and sub_ep.hh_episode_end) ed2
on ep.eci=ed2.eci and ep.hh_episode_bgn=ed2.hh_episode_bgn&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Enterprise Guide throws the error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Teradata prepare: Datatype Mismatch in THEN/ELSE expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't figure out what might be causing that error. It's not the ON variables: there's a join just above this one that uses the exact same tables and variables, and it works fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 15:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Teradata-Datatype-mismatch-error-when-adding-subquery-to-join/m-p/597387#M172117</guid>
      <dc:creator>scify</dc:creator>
      <dc:date>2019-10-17T15:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Teradata: Datatype mismatch error when adding subquery to join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Teradata-Datatype-mismatch-error-when-adding-subquery-to-join/m-p/597563#M172193</link>
      <description>&lt;P&gt;It looks like your ed2 variables have a different type.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 23:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Teradata-Datatype-mismatch-error-when-adding-subquery-to-join/m-p/597563#M172193</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-17T23:07:20Z</dc:date>
    </item>
  </channel>
</rss>

