我有一个表单提示客户名称并将该值传递给查询
FORM compname
customer.cusname
WITH FRAME f1.
UPDATE compname WITH FRAME f1.
此表单将把compname值传递给以下查询
FOR EACH customer WHERE customer.name = compname NO-LOCK :
if available(company) then
do:
CREATE temptt.
assign temptt.num = customer.kco
temptt.no = string(customer.kco)
temptt.name = customer.name
temptt.status = false.
END.
else
message "not matched " view-as alert-box.
end.
我想要做的是,如果搜索没有收到任何行,它应该再次提示输入客户名称。我该怎么做?
我如何在“else block”中再次调用该表单,而且,目前我在该字段中给出了完整的名称,但我想提供名称的一部分,例如,客户名称为“John Smith” Doe“如果我输入”Smith“,它应该检索相关的行。我应该如何改变这里的“Where”条款?请帮帮我。
答案 0 :(得分:1)
重复搜索
这可以通过多种方式完成。这是一个例子:
DEFINE TEMP-TABLE customer NO-UNDO
FIELD cusname AS CHARACTER
FIELD num AS INTEGER.
DEFINE VARIABLE compnum AS INTEGER NO-UNDO.
DEFINE VARIABLE compname AS CHARACTER NO-UNDO.
DEFINE QUERY qSearch FOR customer.
FORM compname compnum WITH FRAME f1.
/* Create some bogus data */
CREATE customer.
ASSIGN customer.cusname = "john doe"
customer.num = 1.
CREATE customer.
ASSIGN customer.cusname = "jane doe"
customer.num = 2.
CREATE customer.
ASSIGN customer.cusname = "name name"
customer.num = 3.
loop:
REPEAT:
CLEAR FRAME f2 ALL.
UPDATE compname compnum WITH FRAME f1.
/* Quit if neither name or number is entered */
IF compname = "" AND compnum = 0 THEN
LEAVE loop.
/* If num is entered - search by it, otherwise by name */
IF compnum <> 0 THEN DO:
OPEN QUERY qSearch FOR EACH customer NO-LOCK WHERE customer.num = compnum.
END.
ELSE DO:
OPEN QUERY qSearch FOR EACH customer NO-LOCK WHERE customer.cusname MATCHES "*" + compname + "*".
END.
GET NEXT qSearch.
DO WHILE AVAILABLE customer:
IF AVAILABLE customer THEN DO:
DISPLAY customer WITH FRAME f2 10 DOWN.
DOWN WITH FRAME f2.
END.
GET NEXT qSearch.
END.
/* If we have results - leave the loop otherwise try again */
IF QUERY qSearch:NUM-RESULTS = 0 THEN
LEAVE loop.
END.
MESSAGE "Quitting" VIEW-AS ALERT-BOX.
搜索部分名称
有几个匹配字符串的运算符:
BEGINS
测试一个字符表达式,以查看该表达式是否以第二个字符表达式开头。
语法:
expression1 BEGINS expression2
示例:
FOR EACH customer WHERE NO-LOCK customer.cusname BEGINS "john":
匹配
将字符表达式与模式进行比较,如果表达式满足模式条件,则计算结果为TRUE值。
模式可以包含通配符:特定位置的句点(。)表示该位置可接受任何单个字符;星号(*)表示可以接受任何字符组,包括空字符组。
语法:
expression1 MATCHES expression2
示例:
FOR EACH customer NO-LOCK WHERE customer.cusname MATCHES "*doe*":
MATCHES听起来像你所追求的但被建议: MATCHES不会利用数据库中的索引,因此将扫描整个表格。这可能/将影响性能,并可能使您的查询需要很长时间。
上面替换为MATCHES的WHERE子句看起来像这样:
FOR EACH customer NO-LOCK WHERE customer.cusname MATCHES "*" + compname + "*":
包含
还有第三个名为CONTAINS的运算符,它使用一种称为WORD索引的东西。这将要求您或您的DBA首先在数据库中创建这些索引。有关单词索引和CONTAINS的更多信息,请参阅在线帮助或此处的PDF:Progress ABL Reference(第1004页)。
CONTAINS可能比MATCHES更好,但还需要您对数据库进行更改。