How Exactly does "Variable for Table" Work in Grids?

I want my Grid’s SQL to work on a table a user selects in Search (the grid opens with search).

Assume the database is called dbase, I have a search (SELECT type) field called {Table} that has this SQL:

SELECT table_name FROM information_schema.tables WHERE table_schema=‘dbase’

In onValidate of the search I have [tablevar] = {Table}, setting a global variable [tablevar] to the selected table.

This works and the tables in dbase are listed for user to choose from.

In onAppInit, I’ve also set [tablevar] = ‘mytable’ (mytable being the default table if nothing was selected in Search.)

In the SQL tab, I have the SQL with “SELECT …FROM mytable…” and for the 2 fields associated with “Variable for table” I have “mytable” and “tablevar”. My understanding is SC should replace mytable with contents of [tablevar] at runtime.

Well, from the results, if I choose any other table it returns no records found. It only finds contents for the default table. Meanwhile the other tables have entries that match the search criteria when I look at phpmyadmin.

There must be some little configuration I’m missing out: grateful for some help.

In the SQL tab, I have the SQL with “SELECT …FROM mytable…” and for the 2 fields associated with “Variable for table” I have “mytable” and “tablevar”. My understanding is SC should replace mytable with contents of [tablevar] at runtime.

Don’t understand :confused:

Never used and nver tried but, looking into it, it suppose you can change fieldNames and table names with vars. But don’t understand how Fields Variables works for example, because you can’t especify more than one var, but help sais:
“Variables for substitution of the field names on the application. For each dynamically determined field, inform the name of the variable and the field that will be substituted.”

It’s a substitution, so let’s say you have SELECT FIELD1, FIELD2 FROM MYTABLE and you wnat to select from any table, with a query like that you have to setup a variable [MYTABNAME] and tell to substitute MYTABLE, I saw that it works in OnScriptInit and or OnAppInit (before the sql is used byt he grid)

so if [MYTABNMAE] = “IRONMAN”

SELECT FIELD1, FIELD2 FROM MYTABLE substitue MYTABLE with what [MYTABNAME] contains and so

SELECT FIELD1, FIELD2 FROM IRONMAN

Sorry to take your time: its working now after a reboot. Must have been some transient problem specific to my environment.