Using a Query to Find a Record
Description
The following script shows how a query works. First, we open a table and set the query dot variable parameters. In this case the default record order is fine. We only filter for records where the field Bill_State_Region equals "MA". Finally, we create the query list.
dim tbl as P dim qry as P dim nrecs as N tbl = table.open("customer") query.filter = "Bill_State_Region = 'MA'" qry = tbl.query_create()
The next two lines demonstrate that we can get the number of records in the query.
nrecs = qry.records_get() ui_msg_box("","The number of matching records is " + nrecs)
The next lines demonstrate how to loop through the records of the query list and process them.
tbl.fetch_first() ui_msg_box("", "The state is " + tbl.Bill_state_region) while .not. tbl.fetch_eof() ' do something interesting with the data tbl.fetch_next() wend
Finally, we clean up.
qry.drop() tbl.close()
Limitations
Desktop applications only. Not available in Community Edition.
See Also