<?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: Adding another subselect into larger SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Adding-another-subselect-into-larger-SQL/m-p/498745#M72524</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;- as this is similar / related to some of your other recent posts, I decided to chime in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's clear to me from the code you shared that the data model is complex, and only a person with a good understanding of the relationships between these tables can provide a good answer.&amp;nbsp; I don't think it's reasonable to expect a solution for the specific code question here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you have questions about good practices for joining tables, using subqueries in the process, or efficiencies that can be gained via a single query instead of multiple table pulls -- then those questions are fair game.&amp;nbsp; Just make sure that the experts here don't need too much domain knowledge about your specific data to respond.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please avoid posting multiple versions of the same/similar question.&amp;nbsp; Since it's the same pool of experts reading/evaluating each topic, it's better if you keep a single topic together in a thread until it's solved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;</description>
    <pubDate>Tue, 25 Sep 2018 14:33:29 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2018-09-25T14:33:29Z</dc:date>
    <item>
      <title>Adding another subselect into larger SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-another-subselect-into-larger-SQL/m-p/498743#M72523</link>
      <description>&lt;P&gt;could someone of you guide me to combine the following SQL into the master SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;SQL to combine in the below master &amp;nbsp;SQL (big one)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select x.policyinstanceid , x.customerID, y.value as client_segment from
(select f.identifier as policyinstanceid , f.customerID
from session.incomm a left join qis.rppolicyinstance f
on a.policyinstanceid=f.identifier) as x left join qis.rpcustomerfield y
on  x.customerid=y.customerid where y.externalidentifier='customerSubsegmentGE'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	connect to &amp;amp;glb_db2.(datasrc=&amp;amp;glb_db2_src. Authdomain=DB2AuthODS connection=global);
	create table incomm2 as
		select * from connection to db2(

with temp1 as (select  y.ExternalIdentifier as commnr,
		y.communicationtypeid,
		y.communicationdescriptionid,
		y.inboxforcommunicationID,
		y.isincoming as incoming,
		y.policyid,
   		y.policyinstanceid,
   		y.tscommunicationcreated,
   		y.datetobecompleted,
   		y.createdbylogonuserid,
		z.externalidentifier as polisnr
from qis.rpcommunication y, qis.rppolicy z
where y.policyid=z.identifier) 

		select b.name as documenttype, b.identifier as communicationdescriptionid,c.identifier as communicationtypeid ,c.externalidentifier,c.Name as commtype,
			e.identifier as createdbylogonuserid,
			e.externalidentifier as creator_duser,	
			e.lastname,e.firstname 
		from temp1 as a
			left join  qis.rpcommunicationdescription as b
				on         a.communicationdescriptionid=b.identifier
			left join  qis.rpcommunicationtype as c
				on         a.communicationtypeid=c.identifier
		left join  
(select distinct identifier as inboxforcommunicationid,name as afdeling from qis.rpinboxforcommunication where identifier in ('00000000001','10000000000','10000000001','10000000003')) as d
				on         a.inboxforcommunicationID=d.inboxforcommunicationid
			left join  qis.rplogonuser as e
				on         a.createdbylogonuserid=e.identifier


);
	disconnect from db2;  
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Master SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 14:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-another-subselect-into-larger-SQL/m-p/498743#M72523</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-09-25T14:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Adding another subselect into larger SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-another-subselect-into-larger-SQL/m-p/498745#M72524</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;- as this is similar / related to some of your other recent posts, I decided to chime in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's clear to me from the code you shared that the data model is complex, and only a person with a good understanding of the relationships between these tables can provide a good answer.&amp;nbsp; I don't think it's reasonable to expect a solution for the specific code question here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you have questions about good practices for joining tables, using subqueries in the process, or efficiencies that can be gained via a single query instead of multiple table pulls -- then those questions are fair game.&amp;nbsp; Just make sure that the experts here don't need too much domain knowledge about your specific data to respond.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please avoid posting multiple versions of the same/similar question.&amp;nbsp; Since it's the same pool of experts reading/evaluating each topic, it's better if you keep a single topic together in a thread until it's solved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 14:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-another-subselect-into-larger-SQL/m-p/498745#M72524</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-09-25T14:33:29Z</dc:date>
    </item>
  </channel>
</rss>

