One option is to use a new namespace for the subquery:
names default to here(1);
// Namespace to share data between background query and this script
ns = new namespace( "subquery" );
// The background query will set to 1 when the background query is complete
ns:isdone = 0;
sql_query = New SQL Query(
Connection( "ODBC:DSN=Test Source;DATABASE=Test;" ),
QueryName( "Thingy" ),
Select( blah ),
From( other blah )
);
sql_query << Run Background(
OnRunComplete(
ns = namespace( "subquery" );
ns:result = queryResult;
ns:dt = data table ( queryResult << Get Name );
ns:isdone = 1;
)
);
//every second check if the query is done (timeout after 10 seconds)
i=0;
while( ( i < 10 ) & ( ns:isdone == 0 ) ,
i++;
if( ns:isdone == 1, show( ns:dt ), show( "Query not done yet." ); wait( 1 ); );
);
//now you can reference the data table
show( ns:dt );
Edit: Here is a link to a similar example:
https://community.jmp.com/t5/JMP-Scripts/Run-queries-in-background-wait-for-them-to-complete-and/ta-...