<?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: New SQL Query -- Join when one dt has variable # of columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/New-SQL-Query-Join-when-one-dt-has-variable-of-columns/m-p/229549#M45574</link>
    <description>Thanks &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;, that is exactly as circuitous as I expected it would be. In the interest of script maintenance (i.e. I don't know what I'm doing and will invariably forget) I might just create a set of default columns that will be incorporated regardless of what data is in them. In anyone thinks of another method, please post!</description>
    <pubDate>Fri, 18 Oct 2019 20:09:15 GMT</pubDate>
    <dc:creator>ionatx</dc:creator>
    <dc:date>2019-10-18T20:09:15Z</dc:date>
    <item>
      <title>New SQL Query -- Join when one dt has variable # of columns</title>
      <link>https://community.jmp.com/t5/Discussions/New-SQL-Query-Join-when-one-dt-has-variable-of-columns/m-p/228195#M45267</link>
      <description>&lt;P&gt;I have a script that joins four tables using the JMP Query Builder. A condensed example of the script is below. This works with a fixed number of columns, however dt1 can have any number of columns and I need to incorporate all of them. The remaining three tables have specific columns for inclusion, all other columns need to be dropped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );

dt1 = Open( "C:\...\dt1.jmp", invisible );
dt2 = Open( "C:\...\dt2.jmp", invisible );

name1 = dt1 &amp;lt;&amp;lt; Get Name;
name2 = dt2 &amp;lt;&amp;lt; Get Name;

list1 = dt1 &amp;lt;&amp;lt; Get Column Names( String );
list2 = dt2 &amp;lt;&amp;lt; Get Column Names( String );

New SQL Query(
	Query name( "dt3" ),
	Connection( "JMP" ),
	Select(
			Column( list1[1], "t1" ),
			Column( list1[2], "t1" ),
			Column( list1[3], "t1" ),
			Column( list2[2], "t2" ),
	),
	From(
		Table( name1, Alias( "t1" ) ),
		Table( name2, Alias( "t2" ),
			Join(
				Type( Inner ),
				GE(
					Column( list1[1], "t1" ), Column( list2[1], "t2" )
				)
			)
		)
	)
) &amp;lt;&amp;lt; Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FOR loops result in "Syntax error in access or evaluation of 'For'".&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	Select(
			For( i = 1, i &amp;lt;= N Items( list1 ), i++,
				Column( list1[i], "t1" ) ),
			Column( list2[2], "t2" ),
	),&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've tried wrapping various parts in EVAL(EVAL EXPR(EXPR())), but no dice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thoughts?&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 06:35:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/New-SQL-Query-Join-when-one-dt-has-variable-of-columns/m-p/228195#M45267</guid>
      <dc:creator>ionatx</dc:creator>
      <dc:date>2019-10-05T06:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: New SQL Query -- Join when one dt has variable # of columns</title>
      <link>https://community.jmp.com/t5/Discussions/New-SQL-Query-Join-when-one-dt-has-variable-of-columns/m-p/228222#M45275</link>
      <description>&lt;P&gt;Here is the brute force method that I use, when I can not figure out a slicker method to solve similar problems.&amp;nbsp; The code simply builds exactly the JSL it needs to run, and then executes it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );

dt1 = Open( "C:\...\dt1.jmp", invisible );
dt2 = Open( "C:\...\dt2.jmp", invisible );

name1 = dt1 &amp;lt;&amp;lt; Get Name;
name2 = dt2 &amp;lt;&amp;lt; Get Name;

list1 = dt1 &amp;lt;&amp;lt; Get Column Names( String );
list2 = dt2 &amp;lt;&amp;lt; Get Column Names( String );

theExpr = "
New SQL Query(
	Query name( \!"dt3\!" ),
	Connection( \!"JMP\!" ),
	Select("
	
	For( i = 1, i &amp;lt;= N Items( list1 ), i++,
		theExpr = theExpr || "Column(" || list1[i] || ", \!"t1\!" ),";
	);
			
	theExpr = theExpr || "Column( list2[2], \!"t2\!" )
	),
	From(
		Table( name1, Alias( \!"t1\!" ) ),
		Table( name2, Alias( \!"t2\!" ),
			Join(
				Type( Inner ),
				GE(
					Column( " || list1[1] || ", \!"t1\!" ), Column( " || list2[1] || ", \!"t2\!" )
				)
			)
		)
	)
) &amp;lt;&amp;lt; Run;";
eval(parse(theExpr));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Oct 2019 20:54:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/New-SQL-Query-Join-when-one-dt-has-variable-of-columns/m-p/228222#M45275</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-10-05T20:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: New SQL Query -- Join when one dt has variable # of columns</title>
      <link>https://community.jmp.com/t5/Discussions/New-SQL-Query-Join-when-one-dt-has-variable-of-columns/m-p/229549#M45574</link>
      <description>Thanks &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;, that is exactly as circuitous as I expected it would be. In the interest of script maintenance (i.e. I don't know what I'm doing and will invariably forget) I might just create a set of default columns that will be incorporated regardless of what data is in them. In anyone thinks of another method, please post!</description>
      <pubDate>Fri, 18 Oct 2019 20:09:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/New-SQL-Query-Join-when-one-dt-has-variable-of-columns/m-p/229549#M45574</guid>
      <dc:creator>ionatx</dc:creator>
      <dc:date>2019-10-18T20:09:15Z</dc:date>
    </item>
  </channel>
</rss>

