AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / ¿Cómo proceder? / Editor de consultas
  • SQL query with a sort performed in the query editor
  • SQL query with sort programmatically
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
To sort (or classify) the records coming from a data file, you have the ability to perform a browse loop on the file by using a key item. In this case, the classifying will be perfomed on the key items only.
The best method to perform this sort (or classifying) consists in using an SQL query.
Let's see how to perform a sort by using:
SQL query with a sort performed in the query editor
The query is used to sort (classify) the records found in a data file according to an item.
In this example, we are going to create an SQL query used to sort the records found in CUSTOMER file according to the customer name.
The different steps for creating this SQL query with sort are as follows:
  1. Click New in the quick access buttons.
    • In the window that is displayed, click "Queries".
    • The query creation wizard starts.
  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. In the left section of the description window, choose the file items that will be used. In our example, we are going to select the CustomerName, Company, ZipCode and City items from the CUSTOMER file.
  6. Double-click the names of the items to add them to the list of query items:
    Selecting the items
  7. To perform a sort, select the item to sort in the middle section. In our example, this item corresponds to "CustomerName".
  8. In the right section of the editor, click the "Sort" button.
    Sort
  9. Select "Sort by the selected item" from the menu that is displayed. The following window appears:
    Sort characteristics
  10. Select the sort order (ascending in our example).
  11. Validate. The query description window is updated: an arrow with the sort number is displayed.
    Query description
  12. Validate the query description window. The query is displayed in the editor:
    View of the query in the editor
  13. Save the query (Ctrl + S).
  14. Press F2 to see the SQL code:
    SQL code of the query
  15. Run the query test (GO in the quick access buttons).
  16. The query can be run in the program by HExecuteQuery.
SQL query with sort programmatically
The SQL queries can be directly written through programming in the WLanguage code. To do so, you must:
  1. Create a variable of type Data source to represent the query at runtime.
  2. Create a Character String variable to contain the SQL code of the query 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
sCodeSQL is string
// Liste des commandes triées par Date et Heure décroissantes
sCodeSQL = [
SELECT COMMANDE.NumCommande,
	COMMANDE.DATECDE,
	COMMANDE.HeureCDE
FROM COMMANDE
ORDER BY DATECDE DESC, HeureCDE DESC
]
HExecuteSQLQuery(Src1, hQueryDefault, sCodeSQL)
FOR EACH Src1
	Trace(Src1.NumCommande, Src1.DATECDE, Src1.HeureCDE)
END
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 23/05/2024

Señalar un error o enviar una sugerencia | Ayuda local