So I dont know anything really about SQL, so I used the JMP Query Builder and based all my code off that.
Basically, I want to allow the user to filter any data they want via a pop up screen where they can pick the column to filter, then what values they want to filter. All the columns in my JMP table are valid column names in my Database. So i got to the point where i created an associative array that holds all the filters and values the user chose where the keys are the filters.
The problem i have is in the New SQL Query where i can use "Where" to do the actual filtering, im not sure how i can add my associative array in.
I'm sure there is a better way to do this. Any thoughts?
_dt = Current Data Table();
selection = Associative Array();
//Create a window to collect filter information
TestIdWindow = New Window( "Filters Window",
<<Modal,
vlb = V List Box(
hlb2 = H List Box( _cbFilters = Combo Box( _dt << Get Column Names( String ) ) ),
hlb3 = H List Box( filtersTextEditBox = Text Edit Box( "", <<SetWidth( 500 ), <<Set Wrap( 480 ) ) ),
FilterTitle = Text Box( "Current Filters" ),
FilterBox = Text Box( "" ),
Button Box( "Add Filter",
totalText = "";
selection[_cbFilters << Get Selected()] = filtersTextEditBox << Get Text();
If( Not( Is Missing( Num( selection[_cbFilters << Get Selected()] ) ) ), //Forces any numerical data to be a number
selection[_cbFilters << Get Selected()] = Num( filtersTextEditBox << Get Text() )
);
currentkey = selection << First;
For( x = 1, x <= N Items( selection ), x++, //Used to print the current filters to the window
totalText = totalText || currentkey || ": " || Char( selection[currentkey] ) || ",";
nextkey = selection << Next( currentkey );
currentkey = nextkey;
);
FilterBox << Set Text( totalText );
),
Button Box( "OK" ),
),
);
currentkey = selection << First;
testVar = {};
For( x = 1, x <= N Items( selection ), x++,
If( Is List( selection[currentkey] ),
,
selection[currentkey] = Eval List( {selection[currentkey]} )
);
Insert Into(
testVar,
Expr(In List(
Column( currentkey, "t1" ),
selection[currentkey],
UI( SelectListFilter( ListBox, Base( "Categorical" ) ) );
)
)
);
currentkey = selection << Next( currentkey );
);
New SQL Query(
Version( 130 ),
Connection(
"Some Server"
),
QueryName( "QueryName" ),
Select(
Distinct,
Column( "Column1", "t1" ),
Column( "Column2", "t1", Analysis Type( "Nominal" ) ),
Column( "Column3", "t1" ),
),
Where(
Eval(testVar[1]);
),
) << Run Foreground( UpdateTable( Current Data Table() ) );