{"title":"Query.Read() Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/query/queryinstance-read-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/query/queryinstance-read-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/query/queryinstance-read-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Reads data from a row in the resulting data set of a query.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":120,"chars":43},{"level":2,"title":"Parameters","slug":"parameters","at":163,"chars":88},{"level":2,"title":"Return Value","slug":"return-value","at":251,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":489,"chars":1307},{"level":2,"title":"Example","slug":"example","at":1796,"chars":1387},{"level":2,"title":"Related information","slug":"related-information","at":3183,"chars":133}],"text":"> Version: _Available or changed with runtime version 1.0._\nReads data from a row in the resulting data set of a query.\n## Syntax\n```al\n[Ok := ]  Query.Read()\n```\n## Parameters\nQuery\nType: query-data-type\nAn instance of the query-data-type data type.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nWhen the Read method is called, the next row in the dataset query is retrieved. While in the reading state, values of columns in the row can be accessed by calling Query.ColumnName, where Query is the query type variable that specifies the query object and ColumnName is the column of the query.\nTo read a row in the dataset, you must call the Open method before the Read method. After the Read method call, columns can be accessed as shown in the following code example.\n```al\nquery.Open;\nquery.Read;\nquery.ColumnName\n\n```\nYou can call the Read method multiple times after the Open method to read consecutive rows in the dataset. The first Read method call retrieves the first row from the resulting dataset and each subsequent Read method retrieves the next row from the dataset. For example, the second Read method call retrieves the second row, the third Read method call retrieves the third row, and so on.\n```al\nQuery.Open;\n// Reads the first row in the dataset.\nQuery.Read;\n// Accesses a column in the first row of the dataset.\nQuery.ColumnName\n// Reads the second row in the dataset.\nQuery.Read;\n// Accesses a column in the first row of the dataset.\nQuery.ColumnName\n```\n> NOTE\n> If the Read method is called and there are no more rows in the dataset, then the Read method returns false.\n## Example\nThe following example demonstrates how to use the Read method on a query. The example code sets filters on the query, opens the query, and then reads the dataset. For each row in the dataset, a message box is displayed that contains the values of the columns in the row.\nThis example requires that you create a query called Customer_SalesQuantity that is links table 18 Customer with table 37 Sales Lines from the CRONUS International Ltd. demonstration database. Include columns for the Name and No. fields from the Customer table and the Quantity field from Sales Lines table.\nThe following AL code opens the query, reads each row of dataset, and then displays a message that has the content of the row. You can add the code to a codeunit, and then run the codeunit to see the results.\n```al\nvar\n  MyQuery: Query \"Customer SalesQuantity\";\n  Text000: Label 'Customer name = %1, Quantity = %2';\nbegin\n    // Sets a filter to display only sales quantities greater than 20.\n    MyQuery.SetFilter(Quantity, '>20');\n    // Runs the query.\n    MyQuery.Open;\n    // Reads each row in the dataset and displays message with column values.\n    // Stops reading when there are no more rows remaining in the dataset (Read is False).\n    while MyQuery.Read do\n    begin\n      Message(Text000, MyQuery.Name, MyQuery.Quantity);\n    end;\n    // Closes the query.\n    MyQuery.Close;\nend;\n```\n## Related information\nquery-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}