<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/discussions/f/general/21653/how-to-insert-value-in-database-table-on-the-basis-of-matching-condition-in-two-table-column-values</link><description>Hi, 
 
 I have below query: 
 
 Suppose, 
 We are having two database tables : Table 1 and Table 2 
 And having column with same name and same type of values in both the tables: column 1 (Table 1) and column 2 (Table 2) 
 We have to match the values of</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84719?ContentTypeID=1</link><pubDate>Wed, 18 Aug 2021 15:52:58 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:134a2508-c861-4b5b-835f-f2cb57b3b7cd</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;So one issue with your current expression is that the a!save() on line 11 won&amp;#39;t work - you can only execute a save in an interface component, not a local variable.&lt;/p&gt;
&lt;p&gt;Also, do you have to query all of the address details to do a comparison? Why can&amp;#39;t you just query the addresses that match your employee details by running the query directly against address? Something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!employee: rule!Get_EmpDetails(),
  local!address: a!queryEntity(
    entity: cons!ADDRESS_DSE
    pagingInfo: a!pagingInfo(
      startIndex: 1,
      batchSize: 1,
    ),
    filter: a!queryFilter(
      field: &amp;quot;Emp_Name&amp;quot;,
      operator: &amp;quot;=&amp;quot;,
      value: local!employee.Emp_Name
    )
  ),
  ...
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84713?ContentTypeID=1</link><pubDate>Wed, 18 Aug 2021 09:04:05 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7631c7e6-149b-49b0-bb3d-0c2f3e795f19</guid><dc:creator>ayushimittal</dc:creator><description>&lt;p&gt;I have tried to implement this by creating two seperate expression rules that are fetching list of Emp_Name from both the table i.e.:&lt;/p&gt;
&lt;p&gt;rule!Get_EmpDetails&lt;pre class="ui-code" data-mode="text"&gt;load(
  local!final,
  local!batch: rule!Get_EmpDetails(),
  local!header: rule!Get_EmpAddressDetails(),
  local!matching: a!forEach(
    items:local!batch,
    expression: with(
      local!val: fv!item,
      a!forEach(
        items: local!header,
        expression: if(exact(fv!item,local!val),&amp;quot;&amp;quot;,a!save(local!final,local!header))
      ))
  ),local!final
      
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;rule!Get_Emp_AddressDetails&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then I have created one expression rule for matching these Emp_Name but gettng null as output.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Attaching the code of expressio rule creted for matching the Emp_Name from both tables.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84700?ContentTypeID=1</link><pubDate>Wed, 18 Aug 2021 03:03:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8239bc24-2f8c-499c-a228-1e1bfc5a05ff</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;Ok makes sense, thanks for the context! In a case like this then I would keep it simple. After the IDP process stores a value in the Emp_Details table, I&amp;#39;d suggest creating a script task that contains a query that returns data from the Emp_Address table. Specifically, you should add a filter to return rows where the employee name matches the name from the Emp_Details table. Then add a gateway directly after this script task. If the query returns no results, then go to a Write to Data Store node and insert a row that contains only the employee name. If the query&amp;nbsp;&lt;em&gt;does&lt;/em&gt; return results, then skip the Write to Data Store node since the value already exists!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84699?ContentTypeID=1</link><pubDate>Wed, 18 Aug 2021 02:34:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:36bf85e5-d89d-4964-b1b6-0ccb5898b998</guid><dc:creator>ayushimittal</dc:creator><description>&lt;p&gt;This is not a one time activity. &lt;/p&gt;
&lt;p&gt;We are implementing IDP in our process. So if pdf read by IDP is having Emp_Name, that name will store in Emp_Details table. &lt;/p&gt;
&lt;p&gt;And now it will match this Emp_Name with Emp_Name in Emp_Address table. If it already exists there, it will do nothing. If not it will insert new row in Emp_Address table with this Emp_Name value and Emp_ Address column will be blank in this new row. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84693?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 19:26:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f958f3c9-79e9-4731-b5e6-5a1f1bde0cee</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;Ok that makes more sense, but I&amp;nbsp;think the part we&amp;#39;re missing is about &lt;em&gt;why&lt;/em&gt; you&amp;#39;re doing this. Is it a one time migration? Is this an Appian process that you expect to run once per day? Depending on the answer to this I&amp;#39;d suggest much different solutions. Like the other poster said, if it&amp;#39;s a one time activity, I&amp;#39;d suggest just doing this on the database as a single migration. If this is on the Appian side, you&amp;#39;ll likely need to query all the data from both tables and use a!forEach() in an expression rule to iterate through the items and update items that don&amp;#39;t exist in table 2.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84687?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 17:23:05 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e2cc5622-4065-4449-a0f0-5d9763781b71</guid><dc:creator>ayushimittal</dc:creator><description>&lt;p&gt;Let me explain you with one example:&lt;/p&gt;
&lt;p&gt;Table 1: Emp_Details (Emp_Id, Emp_Name, Emp_DOB)&lt;/p&gt;
&lt;p&gt;Table 2: Emp_Address (Address_Id, Emp_Name, Emp_Address)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now it should match the value of Emp_Name in both the tables and if no matching is there, It should enter a new row in Emp_Address table having Emp_Name as Emp_Name in Emp_Details table and Emp_Address as blank.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84684?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 17:12:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:283bc87a-8c8a-41d9-8a1d-c227c1d26f56</guid><dc:creator>ayushimittal</dc:creator><description>&lt;p&gt;We need to add the new row in table 2 only if column 1 (table 1) value does not exists among values of column 2 (table 2) .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84683?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 17:10:33 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6d0c6f9a-8dab-43d0-b4d0-da6631c43abf</guid><dc:creator>ayushimittal</dc:creator><description>&lt;p&gt;Table 2 already exists. We just need to add the value of column 2 in new row in table 2 if&amp;nbsp; value of column 1 (table 1) is not present among the row values of column 2 (table 2).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And we need to permanently store these rows.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84681?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 16:57:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3fd14b5e-a7ad-42a9-bd4a-b54ef9d0c499</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;Is this a one time thing or something that you need to do programatically / as part of a process? Also do you need to preserve the existing rows in table 2 or can you just truncate the whole table and add all the new rows?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to insert value in database table on the basis of matching condition in two table column values.</title><link>https://community.appian.com/thread/84680?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 16:16:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a057d2c8-92a1-45fb-bfed-2612a7466b9b</guid><dc:creator>Selvakumar Kumarasamy</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you need to do this at the Appian level (or) at the database level?&lt;/p&gt;
&lt;p&gt;If it is at the Appian level - Consider you&amp;#39;re having 2 variables with the data to insert into 2 tables.&amp;nbsp;Then you can create an expression rule to remove the elements of the 1st array which is already present in the second array.&lt;/p&gt;
&lt;p&gt;If it is at the Database level - You can use a temp table to compare the values present in Table 2 &amp;amp; then insert based on the result.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>