Come posso utilizzare il testo immesso nella casella di testo come variabile in SQL?I'm a beginner with application builders and I want to achieve the following: I'm currently retrieving data from a database using SQL with a specific time period. However, instead of directly modifying the SQL code to change the period, I want to be able to change it via a GUI. I'm currently executing this with JSL, and I want to replace the [HERE] part of the SQL query.
Esempio JSL:
// Get a handle to the data table
dt = Current Data Table();
unique = Function({a}, // input: List, output: List
{aa=Associative Array(),nr=NItems(a),i,aKeys,nUnique,aUnique={}},
For( i=1, i<=nr, i++, aa << insert( a[i] ) );
aKeys = aa << GetKeys;
nUnique = NItems( aKeys );
For( i = 1, i <= nUnique, i++, InsertInto(aUnique,aKeys[i]) );
aUnique
);
dofun = Function({},{months,varName,dType},
months = SampleRateInput << Get;
varName = VarList << GetSelected;
dType = Column(dt,varName[1]) << GetDataType( "English");
If(dType!="Character",
Dialog(Title("Alert"),"Data Type of Variable should be Character. ");
Throw()
);
dt << ClearSelect;
dt << SelectRows( selIdx );
);
OKButtonPress=Function({this},
// This function is called when the OK button is pressed
(thisModuleInstance << Get Box) << Close Window;
dofun;
);
CancelButtonPress=Function({this},
// This function is called when the Cancel button is pressed
(thisModuleInstance << Get Box) << Close Window;
);
New SQL Query(
Version( 130 ),
Connection( ),
QueryName( ),
Select( ),
From(
Table( ),
),
Where(
Custom(
"t1.msr_dt >= DATEADD(month, -[HERE], CURRENT_DATE)",
UI( Custom( Base( "Continuous" ) ) )
)
)
) << Run Foreground( UpdateTable( Current Data Table() ) );
Accesso ai datiRe: Come posso usare il testo immesso nella casella di testo come variabile in SQL?Il mio JMP è la versione 19.
Re: Come posso usare il testo immesso nella casella di testo come variabile in SQL?Hai una tua interfaccia grafica personalizzata che desideri utilizzare per modificare il valore? Riesci a estrarre quel valore? Credo che tu possa semplicemente valutare le variabili all'interno del blocco Where(Custom()) (almeno con JMP18).
Names Default To Here(1);
myval = 150;
dt = New SQL Query(
Version(130),
Connection("JMP"),
JMP Tables(["Big Class" => "\C:\Program Files\JMP\JMPPRO\18\Samples\Data\Big Class.jmp"]),
QueryName("SQLQuery2"),
Select(Column("name", "t1")),
From(Table("SQLQuery1", Alias("t1"))),
Where(
Custom(
Eval Insert("t1.weight >= ^myval^"),
UI(Custom(Base("Continuous"))))
)
) << Run Foreground;
Re: Come posso usare il testo immesso nella casella di testo come variabile in SQL?jthi-san, Arigatougozaimasu.
L'interfaccia grafica descritta in precedenza nel JSL era una versione leggermente ridotta del JSL dell'applicazione di esempio. L'interfaccia grafica che voglio effettivamente creare è simile a quella nell'immagine allegata.
Ho capito che posso passare variabili all'interno di istruzioni SQL racchiudendole tra '^'!
Quale codice JSL dovrei scrivere per eseguire una nuova query SQL quando si preme il pulsante OK nella GUI? 
Re: Come posso usare il testo immesso nella casella di testo come variabile in SQL?Ciao @TamedZebra ,
Non è correlato al lato JSL, ma hai provato ad applicare il Generatore di query del database? Fornisce un'interfaccia grafica che fornisce filtri per modificare gli intervalli di date.
Grazie,
Ben
Re: Come posso usare il testo immesso nella casella di testo come variabile in SQL?@Ben_BarrIngh , Arigatougozaimasu.
È possibile salvare uno script su una tabella dati e, se lo script è scritto come "Query SQL", possiamo aggiornare la tabella dati dal database con un clic.
Ma modificare il codice SQL nello script o nel Query Builder richiede un po' di tempo e un po' di impegno.
Quindi vorrei modificare SQL tramite l'interfaccia grafica che appare premendo uno script su Data-table.

Re: Come posso usare il testo immesso nella casella di testo come variabile in SQL?Non uso un generatore di applicazioni, ma scrivo tutto da solo con JSL. Questa applicazione di esempio non esegue query SQL sul database, ma utilizza una tabella JMP come "database". È una versione piuttosto semplificata, ma può fornire alcune idee generali.
Names Default To Here(1);
initval = 150;
run_query = Expr(
months_to_query = neb_months << get;
dt = New SQL Query(
Version(130),
Connection("JMP"),
JMP Tables(["Big Class" => "\C:\Program Files\JMP\JMPPRO\18\Samples\Data\Big Class.jmp"]),
QueryName("QueryMonths"),
Select(Column("name", "t1")),
From(Table("Big Class", Alias("t1"))),
Where(
Custom(
Eval Insert("t1.weight >= ^months_to_query^"),
UI(Custom(Base("Continuous"))))
)
) << Run Foreground;
wait(0);
nw << Close Window;
);
nw = New Window("Query Data",
V List Box(
Panel Box("How Long",
Lineup Box(N Col(2),
Text Box("Months: "),
neb_months = Number Edit Box(initval),
)
),
Lineup Box(N Col(2),
Button Box("OK",
run_query
),
Button box("Cancel",
nw << close window;
)
)
)
);
Write();
Re: Come posso usare il testo immesso nella casella di testo come variabile in SQL?ottieni --> Ottieni testo
Sono riuscito a eseguire le modifiche sopra menzionate in JMP 19. Sono riuscito a ottenere ciò che volevo. Grazie!!!