{"id":892,"date":"2011-10-18T21:58:42","date_gmt":"2011-10-18T21:58:42","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/techblog\/?p=892"},"modified":"2023-10-05T15:42:51","modified_gmt":"2023-10-05T21:42:51","slug":"joining-tables-with-different-justifications","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/techblog\/?ht_kb=joining-tables-with-different-justifications","title":{"rendered":"Joining Tables with Different Justifications"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>Many people know about <a rel=\"noreferrer noopener\" href=\"\/docs\/knowledge-base\/right-justified-fields-within-web-2-0-applications\" data-type=\"URL\" data-id=\"\/docs\/knowledge-base\/right-justified-fields-within-web-2-0-applications\" target=\"_blank\">*RIGHTJUST<\/a> being able to allow for filtering and record selections when running apps.\u00a0 However, there is also a way to join two tables together on a field that is justified differently (left-justified in one table and right-justified in the other).\u00a0 This tech blog post will cover this specific scenario.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<p>To do so, simply build the app as desired, being sure to join out to the second table.\u00a0 Compile the app and at runtime, the second table&#8217;s records should not be brought in since the different justifications result in no matches.\u00a0 Go back to the interface and open Application Properties.\u00a0 Turn debugging on by changing the radio button next to debug from No to Yes.\u00a0 Run the app again, only this time, copy the SQL statement at the bottom of the page.\u00a0 It should look something like this:<\/p>\n\n\n\n<p><!--MultipleRecordApp: ISSUE 17085. Created: Fri Oct 14 15:24:23 CDT 2011 by DUFFEY. INQHTM-MUL 20070806  --><!-- Begin mrc Style Sheet --><!-- End mrc Style Sheet -->SELECT T01.&#8221;VEND&#8221;, T01.&#8221;INVNO&#8221;, T01.&#8221;BLAH&#8221;, T02.&#8221;INVNO2&#8243;, SUBSTRING(T02.&#8221;INVNO2&#8243;,1,4) FROM MRCWORKLIB.&#8221;TABLEA&#8221; T01 left outer join MRCWORKLIB.&#8221;TABLEB&#8221; T02 ON T01.&#8221;VEND&#8221;=T02.&#8221;VEND&#8221; AND T01.&#8221;INVNO&#8221;=T02.&#8221;INVNO2&#8243; ORDER BY T01.&#8221;VEND&#8221; ASC,T01.&#8221;INVNO&#8221; ASC<\/p>\n\n\n\n<p>In order to join the two tables together, we will use the TRIM() function to remove any padding and left-justify the fields.&nbsp; To do so, find the field that is left justified (INVNO2 from TABLEB, in my example).&nbsp; Immediately before the field type TRIM( and immediately after type ).&nbsp; Using my previous example, the SQL code would now look like:<\/p>\n\n\n\n<p><!--MultipleRecordApp: ISSUE 17085. Created: Fri Oct 14 15:24:23 CDT 2011 by DUFFEY. INQHTM-MUL 20070806  --><!-- Begin mrc Style Sheet --><!-- End mrc Style Sheet -->SELECT T01.&#8221;VEND&#8221;, T01.&#8221;INVNO&#8221;, T01.&#8221;BLAH&#8221;, T02.&#8221;INVNO2&#8243;, SUBSTRING(T02.&#8221;INVNO2&#8243;,1,4) FROM MRCISSUES.&#8221;ISSUE17085&#8243; T01 left outer join MRCISSUES.&#8221;ISS_170852&#8243; T02 ON T01.&#8221;VEND&#8221;=T02.&#8221;VEND&#8221; AND T01.&#8221;INVNO&#8221;=<span style=\"color: #ff0000;\">TRIM(<\/span>T02.&#8221;INVNO2&#8243;<span style=\"color: #ff0000;\">)<\/span> ORDER BY T01.&#8221;VEND&#8221; ASC,T01.&#8221;INVNO&#8221; ASC<\/p>\n\n\n\n<p>Finally, paste this modified SQL code into your app by opening Application Properties and navigating to the SQL tab.&nbsp; Find the text box labeled SQL Statement and paste this modified SQL code into this box.&nbsp; Click OK.&nbsp; Now, at runtime, the two tables will be joined properly since the fields are both left-justified.<\/p>\n\n\n\n<p><strong>Note:<\/strong> If both fields are left-justified AND right-justified within the same column, it may be necessary to TRIM both fields.&nbsp; This is certainly possible.&nbsp; Just keep in mind that using the TRIM function is the same as left-justifying the field.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview Many people know about *RIGHTJUST being able to allow for filtering and record selections when running apps.\u00a0 However, there is also a way to join two tables together on a field that is justified differently (left-justified in one table and right-justified in the other).\u00a0 This tech blog post will&#8230;<\/p>\n","protected":false},"author":3,"comment_status":"closed","ping_status":"open","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[],"ht-kb-tag":[],"class_list":["post-892","ht_kb","type-ht_kb","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=892"}],"version-history":[{"count":4,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/892\/revisions"}],"predecessor-version":[{"id":12189,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/892\/revisions\/12189"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=892"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-category&post=892"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-tag&post=892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}