查询脚本我正在创建一个脚本,该脚本以模式窗口开始,运行几个存储过程并自动连接结果表。这些表相当大,我想为用户添加一个选项来运行类似于查询生成器的程序,他们可以选择列作为过滤器并输入他们想要过滤的数据。
在表格打开之前我该怎么做?我想尽量减少运行过程和连接表格所需的时间,因此在最终表格打开后过滤数据并不是我真正想要做的。
任何建议将不胜感激!
回复:查询脚本对此的一般解决方案将非常复杂。您可以构建一个对话框,其中包含固定数量的选择。
// Get numeric column names from sample data
dt = open("$sample_data\Boston Housing.jmp");
col_list = dt << get column names("String", numeric);
insertinto(col_list, "<NO selection="">", 1);
nw = new window("Get Data2",
panel box("Filter Data",
lineup box(ncol(3),
text box("Column"), text box("Low Value"), text box("High Value"),
cb1 = combo box(col_list),
low1 = number edit box(),
high1 = number edit box(),
cb2 = combo box(col_list),
low2 = number edit box(),
high2 = number edit box(),
cb3 = combo box(col_list),
low3 = number edit box(),
high3 = number edit box(),
// Add more columns if needed...
)
)
);</NO>

回复:查询脚本如果我运行存储过程,获得列及其数据类型的完整列表,并以某种方式将它们用作选项,我是否能够构建过滤器?最终大约有 45 列,所以如果有更好的方法,请告诉我!
回复:查询脚本我该如何让用户选择过滤器?比如,如果我想打开数据表,但我只想知道 :Length 介于 20-40 之间且 :Scale 为 25 纳摩尔。但我希望用户能够从可用列中选择他们想要应用的过滤器。
回复:查询脚本您可以向模式窗口添加提示以预过滤数据。这是一个简单示例,允许用户在查询运行之前预先选择产品和位置。我已经硬编码了可供选择的值列表,但理想情况下,您可以使用 SQL 查询动态获取它。
// Hardcode or get dynamically from the database
product_list = {"AAAA", "BBBB", "CCCC", "DDDD"};
// Hardcode or get dynamically from the database
location_list = {"China", "England", "Germany", "Italy", "Japan", "USA"};
nw = new window("Get Data", << modal,
panel box("Pre-Filter",
hlistbox(
product_cb = listbox(product_list),
location_cb = listbox(location_list)
),
),
panel box("Actions",
hlistbox(
button box("OK",
ok_pushed = 1;
selected_products = product_cb << get selected;
selected_locations = location_cb << get selected
),
button box("Cancel",
ok_pushed = 0;
)
)
)
);
if (ok_pushed,
product_in_list = "";
location_in_list = "";
print(selected_products, selected_locations);
if (nitems(selected_products) > 0,
product_in_list = "t.products IN ('" ||
concat items(selected_products, "', '") || "')";
);
if (nitems(selected_locations) > 0,
location_in_list = "t.locations IN ('" ||
concat items(selected_locations, "', '") || "')";
);
print(product_in_list, location_in_list);
// run SQL query
);

日志输出:
{"AAAA", "CCCC"}
{"England", "Germany", "Italy"}
"t.products IN ('AAAA', 'CCCC')"
"t.locations IN ('England', 'Germany', 'Italy')"