<?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: Scripting: Save SQL Query Results in Project in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Scripting-Save-SQL-Query-Results-in-Project/m-p/681627#M86719</link>
    <description>&lt;P&gt;If you wish to run the query on background and still perform some actions after the query finishes, you can use PostQueryScript&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
obj = New SQL Query(Connection("ODBC:DSN=SampleDSN;"), Custom SQL("SELECT c1, c2, c3 FROM my_table;"));
obj &amp;lt;&amp;lt; Post Query Script("show( queryResult &amp;lt;&amp;lt; Get As Matrix );");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or I think you could also use &lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/sql-messages.shtml?os=win&amp;amp;source=application#ww2231835" target="_blank" rel="noopener"&gt;&amp;lt;&amp;lt;On Run Complete&lt;/A&gt;&amp;nbsp;but you need to add more of the script within that (and you might need global scope...).&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Sep 2023 12:22:13 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2023-09-27T12:22:13Z</dc:date>
    <item>
      <title>Scripting: Save SQL Query Results in Project</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-Save-SQL-Query-Results-in-Project/m-p/681483#M86708</link>
      <description>&lt;P&gt;Hi, probably a newbie question, but I couldn't find a solution myself: I want to save the table generated by an SQL Query via a JSL into a project. The code is below; labels, etc. were omitted. Unfortunately, the dt seems to be deleted after running the query in background. Is it a timing issue? Thanks for any help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query = New SQL Query(
	Connection(""),
	QueryName(""),
	Select(Column("", "t1"), ),
	From(Table("", Schema(""), Alias("t1")), )
);
 
query &amp;lt;&amp;lt; Run Background(OnRunComplete(dt = queryResult));
 
project = New Project();
 
project &amp;lt;&amp;lt; Save As("");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Sep 2023 06:36:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-Save-SQL-Query-Results-in-Project/m-p/681483#M86708</guid>
      <dc:creator>UEJ</dc:creator>
      <dc:date>2023-09-27T06:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting: Save SQL Query Results in Project</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-Save-SQL-Query-Results-in-Project/m-p/681605#M86716</link>
      <description>&lt;P&gt;Running the query in the background causes JMP to not wait for the results before moving on to the next command, so you have to tell it to wait.&amp;nbsp; I generally define dt as Empty() before the query and then tell JMP to wait until dt is scriptable before moving on.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Empty();

query = New SQL Query(
	Connection(""),
	QueryName(""),
	Select(Column("", "t1"), ),
	From(Table("", Schema(""), Alias("t1")), )
);
 
query &amp;lt;&amp;lt; Run Background(OnRunComplete(dt = queryResult));

While( !Is Scriptable( dt ), Wait( 1 ) );
 
project = New Project();
 
project &amp;lt;&amp;lt; Save As("");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Sep 2023 11:10:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-Save-SQL-Query-Results-in-Project/m-p/681605#M86716</guid>
      <dc:creator>mmarchandTSI</dc:creator>
      <dc:date>2023-09-27T11:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting: Save SQL Query Results in Project</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-Save-SQL-Query-Results-in-Project/m-p/681627#M86719</link>
      <description>&lt;P&gt;If you wish to run the query on background and still perform some actions after the query finishes, you can use PostQueryScript&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
obj = New SQL Query(Connection("ODBC:DSN=SampleDSN;"), Custom SQL("SELECT c1, c2, c3 FROM my_table;"));
obj &amp;lt;&amp;lt; Post Query Script("show( queryResult &amp;lt;&amp;lt; Get As Matrix );");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or I think you could also use &lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/sql-messages.shtml?os=win&amp;amp;source=application#ww2231835" target="_blank" rel="noopener"&gt;&amp;lt;&amp;lt;On Run Complete&lt;/A&gt;&amp;nbsp;but you need to add more of the script within that (and you might need global scope...).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 12:22:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-Save-SQL-Query-Results-in-Project/m-p/681627#M86719</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-27T12:22:13Z</dc:date>
    </item>
  </channel>
</rss>

