Query Examples

The Query Object is used to iterate through the record set to do some computation or to check some criteria.

It has a predefined set of steps it follows:

    1. Set Query

    2. Check if there are records

    3. While there are records, do something with the data and go to the next record.

Most  importantly, the Query object has an expression scope.

Example 1. Obtain the total order quantity.

edtSum = 0

Query.SetQuery("QSelectOrders")

WHILE Query.HasRecord()

{

    edtSum = edtSum + Query.GetColumnValue("QTY")

    Query.GoToNext()

}

Note:

Example 2. Obtain the total order quantity for a customer.

edtSum = 0

Query.SetQuery("QSelectOrdersByCustID")

intCUST_ID = lvCustList.GetCurrentRowColumnValue("ID")

Query.SetQueryParam("pCustID", intCUST_ID)

WHILE Query.HasRecord()

{

    edtSum = edtSum + Query.GetColumnValue("QTY")

    Query.GoToNext()

}

Note:

Example 3. Obtain the total order quantity for BrightSoft customer with the use of SetSql method.

edtSum = 0

Query.SetSql("Select QTY from ORDERS where CUST_ID IN (Select ID from CUSTOMER where NAME ='BrightSoft')")

WHILE Query.HasRecord()

{

    edtSum = edtSum + Query.GetColumnValue("QTY")

    Query.GoToNext()

}

Note: