如何將文字方塊中輸入的文字用作 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.
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() ) );
資料存取回覆:如何將文字方塊中輸入的文字用作 SQL 中的變數?我的JMP是19版。
回覆:如何將文字方塊中輸入的文字用作 SQL 中的變數?您是否有自訂的 GUI 來更改值?您能提取該值嗎?我認為您可以直接在 Where(Custom()) 區塊中計算變數(至少使用 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;
回覆:如何將文字方塊中輸入的文字用作 SQL 中的變數?jthi-san,Arigatougozaimasu。
先前 JSL 中描述的 GUI 是範例應用程式 JSL 的精簡版。我實際想要創建的 GUI 就像附圖中那樣。
我知道我可以用「^」括起來的方式在 SQL 語句中傳遞變數!
當按下 GUI 中的「確定」按鈕時,我應該編寫什麼 JSL 程式碼來執行新的 SQL 查詢? 
回覆:如何將文字方塊中輸入的文字用作 SQL 中的變數?你好@TamedZebra ,
與 JSL 方面無關,但您是否嘗試過應用資料庫查詢產生器?它提供了一個 GUI,可提供用於更改日期範圍的過濾器。
謝謝,
本
回覆:如何將文字方塊中輸入的文字用作 SQL 中的變數?@Ben_BarrIngh ,Arigatougozaimasu。
我們可以在資料表上保存一個腳本,如果腳本是“SQL查詢”,我們可以透過一鍵從資料庫更新資料表。
但是在腳本或查詢產生器上更改 SQL 需要花費一些時間和精力。
因此,我想透過在資料表上按下腳本彈出 GUI 來編輯 SQL。

回覆:如何將文字方塊中輸入的文字用作 SQL 中的變數?我不使用應用程式建構器,而是用 JSL 自己編寫所有程式碼。這個範例應用程式不會對資料庫執行 SQL 查詢,而是使用 JMP 表作為「資料庫」。這是一個相當簡化的版本,但可以提供一些通用的思路。
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();
回覆:如何將文字方塊中輸入的文字用作 SQL 中的變數?取得 --> 取得文本
我能夠在 JMP 19 中執行上述更改。我實現了我的目標。謝謝!