<?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: JMP query builder path name issues when selecting tables through a dialogue box in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JMP-query-builder-path-name-issues-when-selecting-tables-through/m-p/890281#M105217</link>
    <description>&lt;P&gt;I would build the table name + link associative array outside of the New SQL Query and the evaluate that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

t1name = "Big Class";
t1path = "$SAMPLE_DATA/Big Class.jmp";

t2path = "$SAMPLE_DATA/Big Class Families.jmp";
t2name = "Big Class Families";

aa = Associative Array();
aa[t1name] = t1path;
aa[t2name] = t2path;

sqlExpr = Expr(
	New SQL Query(
		Version(130),
		Connection("JMP"),
		JMP Tables(_aa_),
		QueryName(_t1name_ || " join " || _t2name_),
		Select,
		From(
			Table(_t1name_, Alias("t1")),
			Table(
				_t2name_,
				Alias("t2"),
				Join(Type(Left Outer), EQ(Column("name", "t1"), Column("name", "t2")))
			)
		)
	) &amp;lt;&amp;lt; Modify
);

q = Substitute(Name Expr(sqlExpr),
	Expr(_aa_), aa,
	Expr(_t1name_), t1name,
	Expr(_t2name_), t2name,
	Expr(_t1path_), t1path,
	Expr(_t2path_), t2path,
);

Eval(q);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Jul 2025 12:01:04 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2025-07-29T12:01:04Z</dc:date>
    <item>
      <title>JMP query builder path name issues when selecting tables through a dialogue box</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-query-builder-path-name-issues-when-selecting-tables-through/m-p/890270#M105216</link>
      <description>&lt;P&gt;I am using a dialogue box to select the primary and secondary tables but when the JMP query builder runs it fails to substitute the file path names correctly, even if I manually resolve this the next time the script needs to reference the tables it falls over&lt;BR /&gt;Error: Name Unresolved: PRIMARYNAME in access or evaluation of 'PRIMARYNAME' , PRIMARYNAME/*###*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Step 1: Get names of all open data tables
dtNames = {};
For(t = 1, t &amp;lt;= N Table(), t++,
	Insert Into(dtNames, Data Table(t) &amp;lt;&amp;lt; Get Name)
);

// Step 2: Dialog to select two tables
nw2 = New Window("Data Table Selector - Note both data tables must be open in this JMP session",
	&amp;lt;&amp;lt;Modal(),
	V List Box(
		Text Box("Select Primary Table (with TS):"),
		lb1 = List Box(dtNames, width(600), nlines(8), MaxItems(1)),
		Spacer Box(Size(10, 10)),
		Text Box("Select Secondary Table (with START/END TIME):"),
		lb2 = List Box(dtNames, width(600), nlines(8), MaxItems(1)),
		Spacer Box(Size(10, 10)),
		H List Box(
			Button Box("OK",
				primaryTableName = lb1 &amp;lt;&amp;lt; Get Selected;
				secondaryTableName = lb2 &amp;lt;&amp;lt; Get Selected;
				If(Is Missing(primaryTableName) | Is Missing(secondaryTableName),
					New Window("Error", &amp;lt;&amp;lt;Modal(), Text Box("Please select both tables."));
					Stop();
				);
				If(primaryTableName == secondaryTableName,
					New Window("Error",
						&amp;lt;&amp;lt;Modal(),
						Text Box("Please select two different tables.")
					);
					Stop();
				);
// Close dialog
				Window(
					"Data Table Selector - Note both data tables must be open in this JMP session"
				) &amp;lt;&amp;lt; Close Window;
			),
			Button Box("Cancel",
				Window(
					"Data Table Selector - Note both data tables must be open in this JMP session"
				) &amp;lt;&amp;lt; Close Window
			)
		)
	)
);

// Step 3: Get references and file paths
dtPrimary = Data Table(primaryTableName[1]);
dtSecondary = Data Table(secondaryTableName[1]);
primaryPath = dtPrimary &amp;lt;&amp;lt; Get Path;
secondaryPath = dtSecondary &amp;lt;&amp;lt; Get Path;

// Check if tables are saved
If(Is Missing(primaryPath) | Is Missing(secondaryPath),
	New Window("Error",
		&amp;lt;&amp;lt;Modal(),
		Text Box("Both tables must be saved JMP files. Please save and try again.")
	);
	Throw("Both tables must be saved JMP files. Please save and try again.");
);

// Step 4: Get all column names from both tables
primaryCols = dtPrimary &amp;lt;&amp;lt; Get Column Names("String");
secondaryCols = dtSecondary &amp;lt;&amp;lt; Get Column Names("String");

// Step 5: Build Select() clause for all columns
selectExprList = {};
For(i = 1, i &amp;lt;= N Items(primaryCols), i++,
	Insert Into(selectExprList, Expr(Column(COLNAME, t1)))
);
For(i = 1, i &amp;lt;= N Items(secondaryCols), i++,
	Insert Into(selectExprList, Expr(Column(COLNAME, t2)))
);

// Substitute actual column names into Select() expressions
For(i = 1, i &amp;lt;= N Items(primaryCols), i++,
	selectExprList[i] = Substitute(selectExprList[i], Expr(COLNAME), primaryCols[i])
);
For(i = 1, i &amp;lt;= N Items(secondaryCols), i++,
	selectExprList[N Items(primaryCols) + i] = Substitute(
			selectExprList[N Items(primaryCols) + i],
		Expr(COLNAME), secondaryCols[i]
	)
);

// Step 6: Build the SQL Query using unquoted Expr tokens for substitution
sqlExpr = Expr(
	New SQL Query(
		Version(130),
		Connection("JMP"),
		JMP Tables(["PRIMARYNAME" =&amp;gt; "PRIMARYPATH", "SECONDARYNAME" =&amp;gt; "SECONDARYPATH"]),
		QueryName(PRIMARYNAME || " join " || SECONDARYNAME),
		Select(__SELECTALLCOLUMNS__),
		From(
			Table(PRIMARYNAME, Alias("t1")),
			Table(
				SECONDARYNAME,
				Alias("t2"),
				Join(
					Type(Left Outer),
					LE(Column("TS", "t1"), Column("END TIME", "t2")) &amp;amp;
					GE(Column("TS", "t1"), Column("START TIME", "t2"))
				)
			)
		)
	) &amp;lt;&amp;lt; Modify
);

// Step 7: Substitute table names, paths, and all columns
sqlExpr = Substitute(sqlExpr,
	"PRIMARYNAME", primaryTableName[1],
	"PRIMARYPATH", primaryPath,
	"SECONDARYNAME", secondaryTableName[1],
	"SECONDARYPATH", secondaryPath,
	Expr(__SELECTALLCOLUMNS__), Expr(selectExprList)
);

// Debug: Show the final SQL Query code (optional, for troubleshooting)
Write(Expr(sqlExpr));

// Step 8: Run the query
Eval(sqlExpr);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit (jthi): added JSL formatting&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2025 11:47:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-query-builder-path-name-issues-when-selecting-tables-through/m-p/890270#M105216</guid>
      <dc:creator>NBrammer</dc:creator>
      <dc:date>2025-07-29T11:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: JMP query builder path name issues when selecting tables through a dialogue box</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-query-builder-path-name-issues-when-selecting-tables-through/m-p/890281#M105217</link>
      <description>&lt;P&gt;I would build the table name + link associative array outside of the New SQL Query and the evaluate that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

t1name = "Big Class";
t1path = "$SAMPLE_DATA/Big Class.jmp";

t2path = "$SAMPLE_DATA/Big Class Families.jmp";
t2name = "Big Class Families";

aa = Associative Array();
aa[t1name] = t1path;
aa[t2name] = t2path;

sqlExpr = Expr(
	New SQL Query(
		Version(130),
		Connection("JMP"),
		JMP Tables(_aa_),
		QueryName(_t1name_ || " join " || _t2name_),
		Select,
		From(
			Table(_t1name_, Alias("t1")),
			Table(
				_t2name_,
				Alias("t2"),
				Join(Type(Left Outer), EQ(Column("name", "t1"), Column("name", "t2")))
			)
		)
	) &amp;lt;&amp;lt; Modify
);

q = Substitute(Name Expr(sqlExpr),
	Expr(_aa_), aa,
	Expr(_t1name_), t1name,
	Expr(_t2name_), t2name,
	Expr(_t1path_), t1path,
	Expr(_t2path_), t2path,
);

Eval(q);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Jul 2025 12:01:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-query-builder-path-name-issues-when-selecting-tables-through/m-p/890281#M105217</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-07-29T12:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: JMP query builder path name issues when selecting tables through a dialogue box</title>
      <link>https://community.jmp.com/t5/Discussions/JMP-query-builder-path-name-issues-when-selecting-tables-through/m-p/890640#M105228</link>
      <description>&lt;P&gt;Thank you I used that concept and solved the problem.&lt;/P&gt;
&lt;P&gt;Final code below in case of use to anyone else&lt;/P&gt;
&lt;P&gt;&amp;lt;&lt;/P&gt;
&lt;P&gt;// Step 1: Get names of all open data tables&lt;BR /&gt;dtNames = {};&lt;BR /&gt;For( t = 1, t &amp;lt;= N Table(), t++,&lt;BR /&gt;Insert Into( dtNames, Data Table( t ) &amp;lt;&amp;lt; Get Name )&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;// Step 2: Dialog to select two tables&lt;BR /&gt;t1name = "";&lt;BR /&gt;t2name = "";&lt;/P&gt;
&lt;P&gt;nw2 = New Window( "Data Table Selector - Note both data tables must be open in this JMP session",&lt;BR /&gt;&amp;lt;&amp;lt;Modal(),&lt;BR /&gt;V List Box(&lt;BR /&gt;Text Box( "Select Primary Table (MES extract table with TS column):" ),&lt;BR /&gt;lb1 = List Box( dtNames, width( 600 ), nlines( 8 ), MaxItems( 1 ) ),&lt;BR /&gt;Spacer Box( Size( 10, 10 ) ),&lt;BR /&gt;Text Box( "Select Secondary Table (Data Table with START/END TIME in columns):" ),&lt;BR /&gt;lb2 = List Box( dtNames, width( 600 ), nlines( 8 ), MaxItems( 1 ) ),&lt;BR /&gt;Spacer Box( Size( 10, 10 ) ),&lt;BR /&gt;H List Box(&lt;BR /&gt;Button Box( "OK",&lt;BR /&gt;t1sel = lb1 &amp;lt;&amp;lt; Get Selected;&lt;BR /&gt;t2sel = lb2 &amp;lt;&amp;lt; Get Selected;&lt;BR /&gt;If( N Items( t1sel ) == 0 | N Items( t2sel ) == 0,&lt;BR /&gt;New Window( "Error", &amp;lt;&amp;lt;Modal(), Text Box( "Please select both tables." ) );&lt;BR /&gt;Stop();&lt;BR /&gt;);&lt;BR /&gt;t1name = t1sel[1];&lt;BR /&gt;t2name = t2sel[1];&lt;BR /&gt;If( t1name == t2name,&lt;BR /&gt;New Window( "Error", &amp;lt;&amp;lt;Modal(), Text Box( "Please select two different tables." ) );&lt;BR /&gt;Stop();&lt;BR /&gt;);&lt;BR /&gt;&lt;BR /&gt;),&lt;BR /&gt;Button Box( "Cancel", nw2 &amp;lt;&amp;lt; Close Window )&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;);&lt;/P&gt;
&lt;P&gt;// Now t1name and t2name are strings with the selected table names&lt;/P&gt;
&lt;P&gt;// Example: Use in SQL Query (assuming both tables are open)&lt;BR /&gt;dtJoin = New SQL Query(&lt;BR /&gt;Version(130),&lt;BR /&gt;Connection("JMP"),&lt;BR /&gt;JMP Tables( Associative Array( {t1name, Data Table(t1name), t2name, Data Table(t2name)} ) ),&lt;BR /&gt;QueryName( t1name || " join " || t2name ),&lt;BR /&gt;&amp;lt;&amp;lt;Select Columns( "All"),&lt;BR /&gt;From(&lt;BR /&gt;Table( t1name, Alias( "t1" ) ),&lt;BR /&gt;Table(&lt;BR /&gt;t2name,&lt;BR /&gt;Alias( "t2" ),&lt;BR /&gt;Join(&lt;BR /&gt;Type( Left Outer ),&lt;BR /&gt;LE( Column( "TS", "t1" ), Column( "END TIME", "t2" ) ) &amp;amp;&lt;BR /&gt;GE( Column( "TS", "t1" ), Column( "START TIME", "t2" ) )&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;) &amp;lt;&amp;lt; Run;&amp;gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2025 16:20:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JMP-query-builder-path-name-issues-when-selecting-tables-through/m-p/890640#M105228</guid>
      <dc:creator>NBrammer</dc:creator>
      <dc:date>2025-07-29T16:20:35Z</dc:date>
    </item>
  </channel>
</rss>

