2014-03-27 28 views
0

返回文本字段塊再次我有一個形式提示用戶名和值傳遞給查詢,從查詢

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塊」中再次調用該表單,並且目前我在該字段中給出完整名稱,但是我想給出部分名稱,例如,客戶名稱是「John Smith Doe「,如果我輸入」Smith「,它應該檢索相關的行。我應該如何修改這個「Where」子句?請幫幫我。

回答

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": 

MATCHES

比較的字符表達式的圖案,如果表達式滿足模式標準評估爲TRUE值。

模式可以包含通配符:特定位置的句號(。)表示任何單個字符在該位置都可以接受;星號(*)表示任何字符組都可以接受,包括空字符組。

語法:

expression1 MATCHES expression2 

例子:

FOR EACH customer NO-LOCK WHERE customer.cusname MATCHES "*doe*": 

火柴聽起來像是你追求的,但被勸:比賽將不使用的數據庫索引使整個表將被掃描。這可能會影響性能,並可能使您的查詢花費很長時間。

WHERE子句用火柴上述替代將是這個樣子:

FOR EACH customer NO-LOCK WHERE customer.cusname MATCHES "*" + compname + "*": 

CONTAINS

還有一個被稱爲第三操作包含使用一種叫做字索引。這將要求您或您的DBA首先在數據庫中創建這些類型的索引。閱讀聯機幫助或在這裏找到的PDF文件,瞭解更多關於詞索引和CONTAINS的信息:Progress ABL Reference(第1004頁)。

CONTAINS可能比MATCHES更好,但也會要求您更改數據庫。

+0

匹配和開始將查找值的結尾和開始部分。但我想檢索結果「John Smith Doe」,所以輸入可能是「John」,「Doe」,「Smith」,但我應該得到結果「John Smith Doe」。這是哪個操作符? – user3427690

+0

BEGINS將尋找開始,MATCHES會尋找任何部分,如果你這樣做的話:field MATCHES「* doe *」 - 在開頭和結尾看到星號。如果你這樣做:字段匹配「約翰*」它將像BEGINS一樣工作(只匹配開頭) - 但仍然沒有索引。就像這樣:匹配只匹配結尾的「* smith」字段。我在上面的答案中增加了一個例子。 – Jensd

+0

嘿,它有很大的幫助。它的工作原理:-) – user3427690