<?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 Query Using Results of Another Query in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/81961#M37026</link>
    <description>&lt;P&gt;Good Morning,&lt;/P&gt;&lt;P&gt;I am wondering if it is possible to use the results of a database query and input them into another query to pull from another database within a JSL?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, one of my scripts will pull the usernames from a db based on predetermined criteria. I then take those user names and run another script to pull additional data on the usernames account. I was hoping there is a way to make the inital pull of usernames and have the JSL input those usernames into the second query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried looking all over and haven't been able to find the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate the help!&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sully&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Oct 2018 15:13:23 GMT</pubDate>
    <dc:creator>Sully</dc:creator>
    <dc:date>2018-10-30T15:13:23Z</dc:date>
    <item>
      <title>Query Using Results of Another Query</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/81961#M37026</link>
      <description>&lt;P&gt;Good Morning,&lt;/P&gt;&lt;P&gt;I am wondering if it is possible to use the results of a database query and input them into another query to pull from another database within a JSL?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, one of my scripts will pull the usernames from a db based on predetermined criteria. I then take those user names and run another script to pull additional data on the usernames account. I was hoping there is a way to make the inital pull of usernames and have the JSL input those usernames into the second query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried looking all over and haven't been able to find the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate the help!&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sully&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 15:13:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/81961#M37026</guid>
      <dc:creator>Sully</dc:creator>
      <dc:date>2018-10-30T15:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Query Using Results of Another Query</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/81974#M37031</link>
      <description>&lt;P&gt;The answer is yes.&amp;nbsp; You can build any subsequent query you need, based upon a previous query(s)&lt;/P&gt;
&lt;P&gt;Here is a simple, and silly example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Run a Query to get one set of information...in this case what ages are
// found for the females
dt = New SQL Query(
	Version( 130 ),
	Connection( "JMP" ),
	JMP Tables(
		["Big Class" =&amp;gt; "\C:\Program Files\SAS\JMPPRO\14\Samples\Data\Big Class.jmp"]
	),
	QueryName( "SQLQuery1" ),
	Select(
		Column(
			"age",
			"t1",
			Analysis Type( "Ordinal" ),
			Numeric Format( "Fixed Dec", "0", "NO", "" )
		)
	),
	From( Table( "Big Class", Alias( "t1" ) ) ),
	Where( Custom( "sex = \!"F\!"", UI( Custom( Base( "Continuous" ) ) ) ) )
) &amp;lt;&amp;lt; Run;

// Find the distinct ages
Summarize( dt, ages = by( :age ) );

// Build the required Where Clause for the next query
queryCode = "age in(" || ages[1];
For( i = 2, i &amp;lt;= N Items( ages ), i++,
	queryCode = queryCode || ", " || ages[i]
);
// Close out the Where Clause
queryCode = queryCode || ")";

New SQL Query(
	Version( 130 ),
	Connection( "JMP" ),
	JMP Tables(
		["Big Class Families" =&amp;gt;
		"\C:\Program Files\SAS\JMPPRO\14\Samples\Data\Big Class Families.jmp"]
	),
	QueryName( "SQLQuery3" ),
	Select(
		Column( "picture", "t1", Analysis Type( "None" ) ),
		Column( "name", "t1" ),
		Column(
			"age",
			"t1",
			Analysis Type( "Ordinal" ),
			Numeric Format( "Fixed Dec", "0", "NO", "" )
		),
		Column( "sex", "t1" ),
		Column( "height", "t1", Numeric Format( "Fixed Dec", "0", "NO", "" ) ),
		Column( "weight", "t1", Numeric Format( "Fixed Dec", "0", "NO", "" ) ),
		Column( "sibling ages", "t1", Analysis Type( "Multiple Response" ) ),
		Column( "sports", "t1", Analysis Type( "Multiple Response" ) ),
		Column( "countries visited", "t1", Analysis Type( "Multiple Response" ) ),
		Column( "family cars", "t1", Analysis Type( "Multiple Response" ) ),
		Column( "reported illnesses", "t1", Analysis Type( "Unstructured Text" ) ),
		Column( "age vector", "t1", Analysis Type( "Vector" ) )
	),
	From( Table( "Big Class Families", Alias( "t1" ) ) ), 
// add the queryCode to the Where() function
	Where( Custom( queryCode, UI( Custom( Base( "Continuous" ) ) ) ) )
) &amp;lt;&amp;lt; Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 16:01:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/81974#M37031</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-10-30T16:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Query Using Results of Another Query</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/81986#M37034</link>
      <description>&lt;P&gt;This might be a simpler example for you to work with.&amp;nbsp; SQL syntax is Oracle.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dbc = create database connection(
"Driver={Oracle in OraClient11g64_home1};UID=bigdatauser;PWD=bigdatapassword;");
user_sql = 
"SELECT DISTINCT u.username 
   FROM bigdata.user_info u
  WHERE u.access_date &amp;gt; to_date('01-Jan-2018','DD-Mon-YYYY')";
user_dt = execute sql(dbc, user_sql);
// Convert list of usernames to IN list
user_list = user_dt:username &amp;lt;&amp;lt; get values;
close(user_dt, nosave);
user_in_list = "IN ('", concat items(user_list, "', '") || "')";
data_sql = evalinsert(
"SELECT m.*
   FROM bigdata.machinery m
  WHERE m.username ^user_in_list^");
data_dt = execute sql(dbc, data_sql);
close database connection(dbc);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 16:41:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/81986#M37034</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-10-30T16:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Query Using Results of Another Query</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/217759#M43523</link>
      <description>&lt;P&gt;Apologizes for the late reply. I kind of dissapeared from the JMP world for a little while.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am back attempthig at it attempting this script. When getting to the portion for creating the user_in_list i continue to receive the error message below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Unexpected ",". Perhaps there is a missing ";" or ",".
Line 54 Column 23: user_in_list = "IN ('"►, concat items(user_list "',
The remaining text that was ignored was
,concat items("user_list"', ')"||"');

user_in_list = "IN ('", concat items(user_list "', '") || "')";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data that I am using is a list of case numbers instead of usernames. Could it be that even though the column is Character the numbers are affecting this line?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again for the help!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 20:54:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/217759#M43523</guid>
      <dc:creator>Sully</dc:creator>
      <dc:date>2019-07-16T20:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Query Using Results of Another Query</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/217761#M43525</link>
      <description>&lt;P&gt;You have a comma where you should have the string concatenation operator ||, and you are missing a comma in concat items.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;user_list = {"a", "b", "c"};
user_in_list = "IN ('" || concat items(user_list, "', '") || "')";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;"IN ('a', 'b', 'c')"&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jul 2019 19:10:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/217761#M43525</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2019-07-16T19:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Query Using Results of Another Query</title>
      <link>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/217773#M43528</link>
      <description>&lt;P&gt;JMP Community does it again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You all are the best. Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 19:35:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Query-Using-Results-of-Another-Query/m-p/217773#M43528</guid>
      <dc:creator>Sully</dc:creator>
      <dc:date>2019-07-16T19:35:09Z</dc:date>
    </item>
  </channel>
</rss>

