Browse widget

shivaprasath143

New Member
In my table i have customer no,name ,country,salary records details.. i want to display only top 5 salary details in my browser.. i need the exact query for it..

thanks in advance

shiva
 

rzr

Member
DEFINE VARIABLE iCnt AS INTEGER NO-UNDO.

DEFINE TEMP-TABLE ttCustomer
FIELDS t_Cust-Num LIKE Customer.Cust-Num
FIELDS t_Name LIKE Customer.Name
FIELDS t_Country LIKE Customer.Country
FIELDS t_Balance LIKE Customer.Balance
INDEX t_Idx t_Balance DESC.

DEFINE QUERY QryttCustomer FOR ttCustomer SCROLLING.
DEFINE BROWSE BrwttCustomer
QUERY QryttCustomer
DISPLAY
ttCustomer.t_Cust-Num LABEL "Cust No#"
ttCustomer.t_Name LABEL "Cust Name"
ttCustomer.t_Country LABEL "Country"
ttCustomer.t_Balance LABEL "Balance"
WITH 5 DOWN MULTIPLE NO-ROW-MARKERS SEPARATORS
WIDTH 72 TITLE "Top 5 Balance".

DEFINE FRAME Fr_Cust BrwttCustomer WITH SIDE-LABELS AT ROW 1 COLUMN 1.

FOR EACH Customer NO-LOCK
BY Balance DESC
iCnt = 1 TO 5 :
CREATE ttCustomer.
ASSIGN t_Cust-Num = Customer.Cust-Num
t_Name = Customer.Name
t_Country = Customer.Country
t_Balance = Customer.Balance.
END.

OPEN QUERY QryttCustomer FOR EACH ttCustomer NO-LOCK .
ENABLE BrwttCustomer WITH FRAME Fr_Cust.
WAIT-FOR "CLOSE" OF THIS-PROCEDURE.
 
try
open query xxx for each table by sortcondition MAX-ROWS 5

but max-rows rule works before sort rule, so there is a chance to get first 5 records and sort them instead top 5. Maybe index can help to extract record in right order.
 

Casper

ProgressTalk.com Moderator
Staff member
The response was already given:

MaximMonin wrote:
[quoute]
Maybe index can help to extract record in right order.
[/quote]

If you need specifically those record then an index is needed to retrieve them in that order.

Regards,

Casper.
 

rzr

Member
if you don't want to use temp-table - then have to add index. In Below ex, I added an Index idxBalance on the Customer table for the field Balance. The output is same here and with the above example using temp-table.

index.JPG

DEFINE VARIABLE iCnt AS INTEGER NO-UNDO.

DEFINE QUERY QryCustomer FOR Customer SCROLLING.
DEFINE BROWSE BrwCustomer
........QUERY QryCustomer
......DISPLAY Customer.Cust-Num LABEL "Cust No#"
..............Customer.Name LABEL "Cust Name"
..............Customer.Country LABEL "Country"
..............Customer.Balance LABEL "Balance"
......WITH 5 DOWN MULTIPLE NO-ROW-MARKERS SEPARATORS
......WIDTH 72 TITLE "Top 5 Balance".

DEFINE FRAME Fr_Cust BrwCustomer WITH SIDE-LABELS AT ROW 1 COLUMN 1.
OPEN QUERY QryCustomer
..FOR EACH Customer USE-INDEX idxBalance NO-LOCK MAX-ROWS 5 .

ENABLE BrwCustomer WITH FRAME Fr_Cust.
WAIT-FOR "CLOSE" OF THIS-PROCEDURE.
 
Top