ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / How to proceed? / Query editor
  • SQL count query on the entire data file
  • SQL count query on a grouping programmatically
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
To count records in a data file, you have the ability to perform a browse loop and to increment an Integer variable.
The best method to perform this count consists in using an SQL query.
SQL count query on the entire data file
This count query is used to count all the records found in a data file. The images present the count of all records found in CUSTOMER file.
The different steps for creating this SQL count query are as follows:
  1. Click New in the quick access buttons.
    • In the window that is displayed, click "Queries".
    • The query creation wizard is launched.
  2. Specify that you want to create a select query ("Select" option).
    Query creation wizard

    Proceed to the next step of the wizard.
  3. The query description window appears.
  4. Give a name and a caption to the query:
    Name and caption of the query
  5. Choose an item (identifier for example) in the data file where the count will be performed.
  6. Add this item to the list of query items.
    Adding the count item
  7. In the right section of the editor, click the "Count" button. In the menu that is displayed, select "Count on the selected item":
    Count menu
    Count description
  8. Validate. The query description window is updated:
    Query description
  9. Validate the query description window. The query is displayed in the editor:
    View of the query in the editor
  10. Save the query (Ctrl + S).
  11. Press F2 to see the SQL code:
    SQL code of the query
  12. Run the query test (GO in the quick access buttons).
  13. The query can be run in the program by HExecuteQuery.
SQL count query on a grouping programmatically
The SQL queries can be directly written through programming in the code. To do so, you must:
  1. Create a Data Source variable to represent the query at runtime
  2. Create a Character String variable to contain the SQL code and write the SQL code in this variable
  3. Run the SQL query with HExecuteSQLQuery
  4. Browse the result with the HReadXXX functions.
Code sample
Src1 is Data Source
sSQLCode is string
// Counts the number of orders by payment type
sSQLCode = [
SELECT PAYMENT.PaymentCap, COUNT(ORDER.OrderID) AS NumberOrders
FROM ORDER, PAYMENT
WHERE ORDER.PaymentID=PAYMENT.PaymentID
GROUP BY PaymentCap
]
HExecuteSQLQuery(Src1, hQueryDefault, sSQLCode)
FOR EACH Src1
	Trace(Src1.LibReglement, Src1.NumberOrders)
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/29/2025

Send a report | Local help