<?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 Joining Two tables on two fields in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Joining-Two-tables-on-two-fields/m-p/291189#M108094</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am finding it hard to join two tables together. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a Master table which has PRFUID, incdate, incnumber, formtype and chiefcomplaint&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This is loaded via SQL as a seperate table and stored into a QVD.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a Patient table which has PRFUID, incdate, incnumber and patientkey&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This is loaded via SQL as a seperate table and stored into a QVD.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to have one table which has the PRFUID, incdate, incnumber, formtype and patientkey within it &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is where I am struggling. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are several form types, Each form is scanned in and given its own PRFUID and some of them don't capture the cheifcomplaint. A patient can have two forms, Form A with a PRFUID of 1001 and form B with an PRFUID of 2002. But both forms will have the incdate and incnumber on them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did join the patient table to the master table as below to get the incdate and the incprfno to build a string that would form a 'key'. I could then use this to link the patient table back to the master table and pull out the cheif complaint.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I join them together? This is what I have accomplished so far, but it is slow and I fear it is causing heavy CPU useage on a limited load.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;TEMP_Patient:&lt;/P&gt;&lt;P&gt;LOAD &lt;BR /&gt; 1 as counter_patient&lt;BR /&gt; ,PRFUniqueId as %KEY_PRFUID&lt;BR /&gt; ,NUM(PatientNo) as PatientNo&lt;BR /&gt; ,EDAccessNum&lt;BR /&gt; ,ContactNumber&lt;BR /&gt; ,AUTONUMBER(upper(anPatFirstNames)&amp;amp;upper(anPatSurname)&amp;amp;patientDOB) as UniquePatientID&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(anPatSurname) as anPatSurname&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(anPatFirstNames) as anPatFirstNames&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(anPatGP) as anPatGP&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(ethnicGroup) as ethnicGroup&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,applymap('Gender', patSex, NULL()) AS Gender&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,patientDOB&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(IF(ISNULL(GPPracticeCode),anPatGPSurg,GPPracticeCode)) AS GPPracticeCode&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(patAddress) as PatientPostcode&lt;BR /&gt; ,left(trim(patAddress),index(trim(patAddress),' ')-1) as PatientPostcodeShort&lt;BR /&gt;//Calc Age from incDate Late&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,IF(ISNULL(PatAgeYearsMonths),patAge,PatAgeYearsMonths) AS patAge&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TRIM(NHSNumber) as NHSNumber&lt;/P&gt;&lt;P&gt;//I have joined the Master table in SQL here to obtain the incdate and incPrfNo.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,num(IncDate)&amp;amp;'-'&amp;amp;num(IncPrfNo) as %KEY_Patient&lt;BR /&gt; ,DATE(IncDate,'dd/mm/yyyy') AS Inc_Date&lt;BR /&gt; ,NUM(IncPrfNo) as IncPrfNo&lt;BR /&gt;;&lt;BR /&gt;SQL SELECT *&lt;BR /&gt;FROM TCMPRF.dbo."LB03_PATIENT" pat&lt;BR /&gt;INNER JOIN&lt;BR /&gt;(SELECT PRFUniqueId FROM [TCMPRF].[dbo].[PE01_MASTER] &lt;BR /&gt;where IncDate between '01-Nov-2008' and getdate()&lt;BR /&gt;//WHERE IncDate &amp;gt;= DateAdd(month,-48,GETDATE())&lt;BR /&gt;) prf&lt;BR /&gt;ON &lt;BR /&gt;pat.PRFUniqueId = prf.PRFUniqueId&lt;BR /&gt;LEFT JOIN&lt;BR /&gt; [TCMPRF].dbo.PE01_MASTER ma&lt;BR /&gt; ON&lt;BR /&gt; pat.PRFUniqueId = ma.PRFUniqueId&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Qualify *;&lt;BR /&gt;UNQUALIFY &lt;BR /&gt;&amp;nbsp; %KEY_Patient&lt;BR /&gt;//&amp;nbsp; ,%KEY_PRFUID&lt;BR /&gt;&amp;nbsp; ,%KEY_Patient&lt;BR /&gt;&amp;nbsp; ,Patient.ChiefComplaintOriginal&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;Patient:&lt;BR /&gt;Load &lt;BR /&gt; TEMP_Patient.counter_patient as counter_patient&lt;BR /&gt;// ,%KEY_PRFUID&lt;BR /&gt; ,TEMP_Patient.PatientNo as PatientNo&lt;BR /&gt; ,TEMP_Patient.EDAccessNum as EDAccessNum&lt;BR /&gt; ,TEMP_Patient.ContactNumber as ContactNumber&lt;BR /&gt; ,TEMP_Patient.UniquePatientID as UniquePatientID&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.anPatSurname as anPatSurname&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.anPatFirstNames as anPatFirstNames&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.anPatGP as anPatGP&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.ethnicGroup as ethnicGroup&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.Gender as Gender&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.patientDOB as patientDOB&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.GPPracticeCode as GPPracticeCode&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.PatientPostcode as PatientPostcode&lt;BR /&gt; ,TEMP_Patient.PatientPostcodeShort as PatientPostcodeShort&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.patAge as patAge&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.NHSNumber as NHSNumber&lt;BR /&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp; ,%KEY_Patient as %KEY_Patient_test&lt;BR /&gt;// ,TEMP_Patient.Inc_Date as Inc_Date&lt;BR /&gt; &lt;BR /&gt;Resident TEMP_Patient;&lt;/P&gt;&lt;P&gt;left join &lt;BR /&gt;Load &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %KEY_Patient&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,Master.ChiefComplaintOriginal as Patient.ChiefComplaintOriginal&lt;BR /&gt;resident Master; &lt;/P&gt;&lt;P&gt;DROP Table TEMP_Patient&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Many thanks in advance for any guidance. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 19 Jul 2011 16:01:10 GMT</pubDate>
    <dc:creator />
    <dc:date>2011-07-19T16:01:10Z</dc:date>
    <item>
      <title>Joining Two tables on two fields</title>
      <link>https://community.qlik.com/t5/QlikView/Joining-Two-tables-on-two-fields/m-p/291189#M108094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am finding it hard to join two tables together. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a Master table which has PRFUID, incdate, incnumber, formtype and chiefcomplaint&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This is loaded via SQL as a seperate table and stored into a QVD.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a Patient table which has PRFUID, incdate, incnumber and patientkey&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This is loaded via SQL as a seperate table and stored into a QVD.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to have one table which has the PRFUID, incdate, incnumber, formtype and patientkey within it &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is where I am struggling. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are several form types, Each form is scanned in and given its own PRFUID and some of them don't capture the cheifcomplaint. A patient can have two forms, Form A with a PRFUID of 1001 and form B with an PRFUID of 2002. But both forms will have the incdate and incnumber on them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did join the patient table to the master table as below to get the incdate and the incprfno to build a string that would form a 'key'. I could then use this to link the patient table back to the master table and pull out the cheif complaint.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I join them together? This is what I have accomplished so far, but it is slow and I fear it is causing heavy CPU useage on a limited load.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;TEMP_Patient:&lt;/P&gt;&lt;P&gt;LOAD &lt;BR /&gt; 1 as counter_patient&lt;BR /&gt; ,PRFUniqueId as %KEY_PRFUID&lt;BR /&gt; ,NUM(PatientNo) as PatientNo&lt;BR /&gt; ,EDAccessNum&lt;BR /&gt; ,ContactNumber&lt;BR /&gt; ,AUTONUMBER(upper(anPatFirstNames)&amp;amp;upper(anPatSurname)&amp;amp;patientDOB) as UniquePatientID&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(anPatSurname) as anPatSurname&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(anPatFirstNames) as anPatFirstNames&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(anPatGP) as anPatGP&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(ethnicGroup) as ethnicGroup&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,applymap('Gender', patSex, NULL()) AS Gender&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,patientDOB&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(IF(ISNULL(GPPracticeCode),anPatGPSurg,GPPracticeCode)) AS GPPracticeCode&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,UPPER(patAddress) as PatientPostcode&lt;BR /&gt; ,left(trim(patAddress),index(trim(patAddress),' ')-1) as PatientPostcodeShort&lt;BR /&gt;//Calc Age from incDate Late&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,IF(ISNULL(PatAgeYearsMonths),patAge,PatAgeYearsMonths) AS patAge&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TRIM(NHSNumber) as NHSNumber&lt;/P&gt;&lt;P&gt;//I have joined the Master table in SQL here to obtain the incdate and incPrfNo.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,num(IncDate)&amp;amp;'-'&amp;amp;num(IncPrfNo) as %KEY_Patient&lt;BR /&gt; ,DATE(IncDate,'dd/mm/yyyy') AS Inc_Date&lt;BR /&gt; ,NUM(IncPrfNo) as IncPrfNo&lt;BR /&gt;;&lt;BR /&gt;SQL SELECT *&lt;BR /&gt;FROM TCMPRF.dbo."LB03_PATIENT" pat&lt;BR /&gt;INNER JOIN&lt;BR /&gt;(SELECT PRFUniqueId FROM [TCMPRF].[dbo].[PE01_MASTER] &lt;BR /&gt;where IncDate between '01-Nov-2008' and getdate()&lt;BR /&gt;//WHERE IncDate &amp;gt;= DateAdd(month,-48,GETDATE())&lt;BR /&gt;) prf&lt;BR /&gt;ON &lt;BR /&gt;pat.PRFUniqueId = prf.PRFUniqueId&lt;BR /&gt;LEFT JOIN&lt;BR /&gt; [TCMPRF].dbo.PE01_MASTER ma&lt;BR /&gt; ON&lt;BR /&gt; pat.PRFUniqueId = ma.PRFUniqueId&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Qualify *;&lt;BR /&gt;UNQUALIFY &lt;BR /&gt;&amp;nbsp; %KEY_Patient&lt;BR /&gt;//&amp;nbsp; ,%KEY_PRFUID&lt;BR /&gt;&amp;nbsp; ,%KEY_Patient&lt;BR /&gt;&amp;nbsp; ,Patient.ChiefComplaintOriginal&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;Patient:&lt;BR /&gt;Load &lt;BR /&gt; TEMP_Patient.counter_patient as counter_patient&lt;BR /&gt;// ,%KEY_PRFUID&lt;BR /&gt; ,TEMP_Patient.PatientNo as PatientNo&lt;BR /&gt; ,TEMP_Patient.EDAccessNum as EDAccessNum&lt;BR /&gt; ,TEMP_Patient.ContactNumber as ContactNumber&lt;BR /&gt; ,TEMP_Patient.UniquePatientID as UniquePatientID&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.anPatSurname as anPatSurname&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.anPatFirstNames as anPatFirstNames&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.anPatGP as anPatGP&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.ethnicGroup as ethnicGroup&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.Gender as Gender&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.patientDOB as patientDOB&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.GPPracticeCode as GPPracticeCode&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.PatientPostcode as PatientPostcode&lt;BR /&gt; ,TEMP_Patient.PatientPostcodeShort as PatientPostcodeShort&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.patAge as patAge&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,TEMP_Patient.NHSNumber as NHSNumber&lt;BR /&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp; ,%KEY_Patient as %KEY_Patient_test&lt;BR /&gt;// ,TEMP_Patient.Inc_Date as Inc_Date&lt;BR /&gt; &lt;BR /&gt;Resident TEMP_Patient;&lt;/P&gt;&lt;P&gt;left join &lt;BR /&gt;Load &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %KEY_Patient&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,Master.ChiefComplaintOriginal as Patient.ChiefComplaintOriginal&lt;BR /&gt;resident Master; &lt;/P&gt;&lt;P&gt;DROP Table TEMP_Patient&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Many thanks in advance for any guidance. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2011 16:01:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Joining-Two-tables-on-two-fields/m-p/291189#M108094</guid>
      <dc:creator />
      <dc:date>2011-07-19T16:01:10Z</dc:date>
    </item>
  </channel>
</rss>

