テキストボックスに入力したテキストを 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() ) );
データアクセスRe: テキストボックスに入力したテキストを SQL の変数として使用するにはどうすればよいですか?私のJMPはバージョン19です。
Re: テキストボックスに入力したテキストを 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;
Re: テキストボックスに入力したテキストを SQL の変数として使用するにはどうすればよいですか?jthi-san, Arigatougozaimasu.
先ほどJSLで記述したGUIは、サンプルアプリケーションのJSLを少し簡略化したものでした。実際に作成したいGUIは、添付画像のようなものです。
変数を '^' で囲むことで、SQL ステートメント内で変数を渡すことができることを理解しました。
GUI の [OK] ボタンが押されたときに新しい SQL クエリを実行するには、どのような JSL コードを記述する必要がありますか? 
Re: テキストボックスに入力したテキストを SQL の変数として使用するにはどうすればよいですか?こんにちは、 @TamedZebraさん、
JSL 側とは関係ありませんが、データベースクエリ ビルダーを適用してみたことはありますか? クエリ ビルダーは、日付範囲を変更するためのフィルターを提供する GUI を提供します。
ありがとう、
ベン
Re: テキストボックスに入力したテキストを SQL の変数として使用するにはどうすればよいですか?@Ben_BarrIngh , Arigatougozaimasu.
データ テーブルにスクリプトを保存することができ、スクリプトが「SQL クエリ」で記述されている場合は、ワンクリックでデータベースからデータ テーブルを更新できます。
ただし、スクリプトまたはクエリ ビルダーで SQL を変更するには、少しの時間と労力がかかります。
そこで、データテーブル上のスクリプトを押して GUI をポップアップ表示し、SQL を編集したいと思います。

Re: テキストボックスに入力したテキストを 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();
Re: テキストボックスに入力したテキストを SQL の変数として使用するにはどうすればよいですか?get --> テキストを取得
JMP 19で上記の変更を実行できました。望みどおりの結果が得られました。ありがとうございます!!!