我有一个组合框小部件。我想创建一个依赖于组合框的WHERE语句。
如果组合框的值为0,则应显示所有客户。如果值与0不同,则只显示符合组合框值的客户。
示例:
Assign CB-Customer.
For each Customer WHERE /* after that*/
/* something like this
IF CB-CUstomer = 0 THEN ASSIGN Customer.CustNum >= 0 .
ELSE ASSIGN Customer.CustNum = CB-Customer .
*/
我以前见过这样的代码,但我无法弄清楚它是如何工作的。
答案 0 :(得分:3)
为什么不定义查询并根据CB-Customer打开它,而不是将WHERE短语中的两个条件组合在一起(这可能会消除使用索引的任何机会)。
DEFINE QUERY q-Customer FOR Customer.
IF CB-Customer = 0 THEN DO:
OPEN QUERY q-Customer
FOR EACH Customer
WHERE Customer.CustNum >= 0
NO-LOCK
.
END.
ELSE DO:
OPEN QUERY q-Customer
FOR EACH Customer
WHERE Customer.CustNum = CB-Customer
NO-LOCK
.
END.
GET FIRST q-Customer.
REPEAT WHILE AVAILABLE Customer:
/* Whatever you want to do with the Customer record, for example: */
DISPLAY Customer.
GET NEXT q-Customer.
END.
您可以使用查询做很多花哨的技巧,尤其是动态查询,但这应该适用于几乎每个最新版本的OpenEdge。
答案 1 :(得分:1)
FOR EACH Customer
WHERE (CB-CUstomer = 0 AND Customer.CustNum >= 0)
OR Customer.CustNum = CB-CUstomer:
END.
如果我理解你的问题,这应该可以做你想要的。
答案 2 :(得分:1)
我理解你的问题:
如果组合框的值为零,则您希望显示所有客户。否则,您只想显示与客户编号匹配的客户?
你可以用一个条件做一个WHERE子句,但我会避免它。在这种情况下,查询是非常基本的,但是当它们变得更复杂(并且它们确实)时,其中具有条件的子句很难阅读和理解。但我想这也与个人选择有关。
FOR EACH Customer NO-LOCK WHERE
Customer.CustNum = (IF CB-Customer = 0 THEN Customer.CustNum ELSE CB-Customer ):
MESSAGE Customer.CustNum.
END.
我更愿意做两个单独的FOR EACH'es:
IF CB-Customer = 0 THEN DO:
/* TABLE-SCAN is a quite new thing, might not work in your version */
FOR EACH Customer NO-LOCK TABLE-SCAN:
MESSAGE Customer.CustNum.
END.
END.
ELSE DO:
FOR EACH Customer NO-LOCK WHERE Customer.CustNum = CB-Customer:
MESSAGE Customer.CustNum.
END.
END.
或带有单独QUERY-PREPARE语句的QUERY:
DEFINE QUERY q FOR Customer.
DEFINE VARIABLE cQuery AS CHARACTER NO-UNDO.
ASSIGN CB-Customer.
IF CB-Customer = 0 THEN DO:
cQuery = "FOR EACH Customer NO-LOCK".
END.
ELSE DO:
cQuery = "FOR EACH Customer NO-LOCK WHERE Customer.CustNum = " + QUOTER(cb-customer).
END.
MESSAGE cQuery.
QUERY q:QUERY-PREPARE(cQuery).
QUERY q:QUERY-OPEN().
GET FIRST q.
REPEAT WHILE AVAILABLE Customer:
MESSAGE Customer.CustNum.
GET NEXT q.
END.