<?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: How to append legacy data table with new data from database script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253611#M49790</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have another solution I think might work.&amp;nbsp; The concatenate function is back to appending to the first table (dt1), but now creates a source column to keep track of which rows were in dt1 and which were appended from dt2.&amp;nbsp; "Onruncomplete" now gets the name of table dt2 and then looks for the ":Source table" column, selecting and deleting the "dt2" rows.&amp;nbsp; It then deletes ":Source table."&amp;nbsp; Please try that and let me know if this works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query&amp;lt;&amp;lt;Run(onruncomplete(

dt2=queryResult;
dt2name=dt2&amp;lt;&amp;lt;get name();

try(
	dt1&amp;lt;&amp;lt;select where(:Source Table==dt2name)&amp;lt;&amp;lt;delete rows;
	dt1&amp;lt;&amp;lt;Delete Columns(:Source Table);
);

dt1&amp;lt;&amp;lt;Concatenate(dt2, append to first table,create source column);
Close(dt2,nosave))
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 22 Mar 2020 11:51:57 GMT</pubDate>
    <dc:creator>HadleyMyers</dc:creator>
    <dc:date>2020-03-22T11:51:57Z</dc:date>
    <item>
      <title>How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/252780#M49623</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a static JMP data table that contains old, historical information (legacy data).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another JMP data table that contains new data. This table is fed from a database through a JMP database query. That also means JMP automatically provides me with a nice script that allows to update the table from the database each time I run it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I want to have the old table appended with the new data that is being pulled from the database, obviously without losing the old data. Probably JSL is needed for this, but I can't figure it out myself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help gladly appreciated,&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;Guy&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 16:01:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/252780#M49623</guid>
      <dc:creator>guyvanhove</dc:creator>
      <dc:date>2020-03-17T16:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/252788#M49626</link>
      <description>&lt;P&gt;Hi Guy,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When running the SQL query (New SQL Query(...)), you can get a reference to the data table by the following method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1)run the query and save the source script, giving the query a new name: queryname = New SQL Query(...)&amp;lt;&amp;lt;Run;&lt;/P&gt;
&lt;P&gt;2) Delete the &amp;lt;&amp;lt;Run part after the query, so you just have New SQL Query (...);&lt;/P&gt;
&lt;P&gt;3) Add a line of script below that: queryname&amp;lt;&amp;lt;Run(onruncomplete(dt=queryResult));&lt;/P&gt;
&lt;P&gt;4) use the reference to dt with a "Concatenate" function together with the other table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try this and let me know if you can make it work for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 16:52:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/252788#M49626</guid>
      <dc:creator>HadleyMyers</dc:creator>
      <dc:date>2020-03-17T16:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253354#M49728</link>
      <description>&lt;P&gt;Hi Hadley,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand all of the steps yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) run the query and save the source script, giving the query a new name: queryname = New SQL Query(...)&amp;lt;&amp;lt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt; with "save the source script", do you mean I just have to EDIT the existing query in my&amp;nbsp;table&amp;nbsp;and save it there? Or add it as a NEW script to my&amp;nbsp;table? Or save this new script elsewhere?&lt;/P&gt;&lt;P&gt;4) use the reference to dt with a "Concatenate" function together with the other table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt; this needs more clarification I'm afraid&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance Hadley!&lt;/P&gt;&lt;P&gt;Guy&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 08:27:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253354#M49728</guid>
      <dc:creator>guyvanhove</dc:creator>
      <dc:date>2020-03-20T08:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253420#M49748</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think we can probably simplify this through the following: we'll call dt1 the table that was saved on our desktop, and dt2 the new table that we want to update from our database.&amp;nbsp; We are going to create a new table script to table dt1 that creates a query for dt2, and then concatenates dt1 and dt2 together, appending the results to dt1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1=Current data table();&lt;BR /&gt;&lt;BR /&gt;queryname=New&amp;nbsp;SQL Query(...&lt;BR /&gt;...);&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;queryname&amp;lt;&amp;lt;Run(onruncomplete(dt2=queryResult));&lt;BR /&gt;&lt;BR /&gt;dt1&amp;lt;&amp;lt;Concatenate(dt2,Append to first table);&lt;/SPAN&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To answer your first question, you can get the New SQL Query script from dt2 by running the query and then right-clicking on the source script, saving the result to your clipboard, and then pasting it into a new script window.&amp;nbsp; You can then use the window to work on the script before saving it to a New Table Script in dt1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this helpful?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 15:13:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253420#M49748</guid>
      <dc:creator>HadleyMyers</dc:creator>
      <dc:date>2020-03-20T15:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253553#M49770</link>
      <description>&lt;P&gt;Hi Hadley,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think we are close...&lt;/P&gt;&lt;P&gt;I think I executed everything as you suggested, but when I just open the dt1 and run the script from there, I get this JMP Alert message:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Name Unresolved: dt2 in access or evaluation of 'dt2', dt2/*###*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Shortly after, the dt2 datatable pops up. But it's not appended to dt1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Interestingly, when I close this dt2 and try running the script from dt1 again, I no longer get the JMP Alert message, but now the Concatenate window pops up, and shortly after the dt2 pops up again. Still dt2 is not appended to dt1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Guy&lt;/P&gt;</description>
      <pubDate>Sat, 21 Mar 2020 16:09:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253553#M49770</guid>
      <dc:creator>guyvanhove</dc:creator>
      <dc:date>2020-03-21T16:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253554#M49771</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OK, I think I have a solution. As you can see from the script below, I've added the Concatenate function to the inside of the "onruncomplete" message.&amp;nbsp; If this is saved as a table script to dt1, that should work.&amp;nbsp; Please try it and let me know.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1=Current Data Table();

query=New SQLQuery (...
);

query&amp;lt;&amp;lt;Run(onruncomplete(dt2=queryResult;dt1&amp;lt;&amp;lt;Concatenate(dt2,Append to first table);));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Mar 2020 16:46:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253554#M49771</guid>
      <dc:creator>HadleyMyers</dc:creator>
      <dc:date>2020-03-21T16:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253557#M49773</link>
      <description>&lt;P&gt;Yes, this does the trick, it gets appended. Two remaining issues still:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) A minor issue is that the dt2 table still&amp;nbsp;pops up separately as well, which is not needed.&lt;/P&gt;
&lt;P&gt;I tried to avoid this by changing the script as follows, but the result is the same:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;queryname &amp;lt;&amp;lt; Run( onruncomplete( dt1 &amp;lt;&amp;lt; Concatenate( dt2 = queryResult, Append to first table ) ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;queryname &amp;lt;&amp;lt; Run(
	onruncomplete(
		dt2 = queryResult;
		dt1 &amp;lt;&amp;lt; Concatenate( dt2, Append to first table );
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) A bigger issue is&amp;nbsp;that when the script is run a second time, the same data gets appended again at the end of dt1. I need some sort of rule that only imports any new data. Not sure if this can be done in the Concatenate portion of the script.&lt;/P&gt;
&lt;P&gt;If there is no workaround for this, as a plan B we may also try to modify the script such that it spits out the appended table (dt1 + dt2) as a seperate table. That way the dt1 can always be used as the basis for future data updates.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 23:50:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253557#M49773</guid>
      <dc:creator>guyvanhove</dc:creator>
      <dc:date>2020-03-22T23:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253560#M49775</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding a Close() function to the onruncomplete script will make dt2 open and close so quickly the user won't know it happened:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query&amp;lt;&amp;lt;Run(onruncomplete(dt2=queryResult;dt1&amp;lt;&amp;lt;Concatenate(dt2);Close(dt2,nosave)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice that I also removed the "Append to first table" statement from the concatenate function.&amp;nbsp; This will create a separate table and leave dt1 intact.&amp;nbsp; That would coincide with your suggested workaround (good idea, by the way!).&amp;nbsp; There's probably an easy way of checking each row of both tables and only appending rows that are unique to dt2, but I can't think of it.&amp;nbsp; Maybe someone else has a suggestion?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Mar 2020 18:40:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253560#M49775</guid>
      <dc:creator>HadleyMyers</dc:creator>
      <dc:date>2020-03-21T18:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253561#M49776</link>
      <description>&lt;P&gt;Hi again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thinking about it a little more, you could always add a command to remove duplicate rows from dt1 after appending dt2 to dt1.&amp;nbsp; That might resolve the 2nd issue you had.&amp;nbsp;&lt;LI-MESSAGE title="Selecting and removing duplicates row with condition" uid="220631" url="https://community.jmp.com/t5/Discussions/Selecting-and-removing-duplicates-row-with-condition/m-p/220631#U220631" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 23:51:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253561#M49776</guid>
      <dc:creator>HadleyMyers</dc:creator>
      <dc:date>2020-03-22T23:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253608#M49788</link>
      <description>&lt;P&gt;Thanks Hadley.&lt;/P&gt;&lt;P&gt;I just added that entire command to the end of my script, changed dt to dt1 (although that shouldn't even matter I think), saved it and ran it. The script still runs without errors or alert messages, but when I run it a second time the duplicates keep on being added.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 07:49:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253608#M49788</guid>
      <dc:creator>guyvanhove</dc:creator>
      <dc:date>2020-03-22T07:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253611#M49790</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have another solution I think might work.&amp;nbsp; The concatenate function is back to appending to the first table (dt1), but now creates a source column to keep track of which rows were in dt1 and which were appended from dt2.&amp;nbsp; "Onruncomplete" now gets the name of table dt2 and then looks for the ":Source table" column, selecting and deleting the "dt2" rows.&amp;nbsp; It then deletes ":Source table."&amp;nbsp; Please try that and let me know if this works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query&amp;lt;&amp;lt;Run(onruncomplete(

dt2=queryResult;
dt2name=dt2&amp;lt;&amp;lt;get name();

try(
	dt1&amp;lt;&amp;lt;select where(:Source Table==dt2name)&amp;lt;&amp;lt;delete rows;
	dt1&amp;lt;&amp;lt;Delete Columns(:Source Table);
);

dt1&amp;lt;&amp;lt;Concatenate(dt2, append to first table,create source column);
Close(dt2,nosave))
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Mar 2020 11:51:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253611#M49790</guid>
      <dc:creator>HadleyMyers</dc:creator>
      <dc:date>2020-03-22T11:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253646#M49800</link>
      <description>&lt;P&gt;Yes! It works as expected now! Thanks Hadley!&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 22:20:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253646#M49800</guid>
      <dc:creator>guyvanhove</dc:creator>
      <dc:date>2020-03-22T22:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to append legacy data table with new data from database script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253690#M49811</link>
      <description>Perfect!</description>
      <pubDate>Mon, 23 Mar 2020 07:01:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-append-legacy-data-table-with-new-data-from-database/m-p/253690#M49811</guid>
      <dc:creator>HadleyMyers</dc:creator>
      <dc:date>2020-03-23T07:01:15Z</dc:date>
    </item>
  </channel>
</rss>

