topic hubReporting & Analyticsofficial - Microsoftreviewed - checked by Opus

Using Query objects

Query objects in AL: how to define dataitems and columns, link and join tables, filter, aggregate, extract date parts, read results in code, and analyze query data interactively. It answers questions about building and using queries instead of record variables.

Path: Development > Programming in the AL language > Tables and data > Using Query objects · tier official · system reporting · narrative reviewed (checked by Opus)

Overview

Query objects retrieve and combine records from one or more tables into a single dataset. They can calculate totals, group rows, and be exposed as OData web services. Queries can be normal or API queries, and they can be opened in data analysis mode.

The pages follow the path of building a query. The overview and Query object pages explain what a query is and its discoverability properties. Data Item Links covers joining tables with DataItemLink and SqlJoinType. Filtering, aggregation, and date methods shape the dataset. Accessing Columns and Using Queries Instead of Record Variables show how to open, read, and use the results in AL code. The data analysis page covers interactive analysis of list page and query data without running reports.

Start with Query Overview, then read Data Item Links and Filtering in Query objects. Move to aggregation, date data, and code access as needed.

Key points

  • Queries combine records from one or more tables into one dataset, can calculate totals and group rows, and can be exposed as OData web services.
  • Data Item Links use DataItemLink and SqlJoinType, with InnerJoin, LeftOuterJoin, RightOuterJoin and FullOuterJoin, plus cross joins.
  • Filtering options: DataItemTableFilter property, ColumnFilter property, filter rows, and SetFilter/SetRange methods.
  • Aggregation uses the column Method property (Sum, Average, Min, Max, Count) across grouped records.
  • Day, Month and Year methods in query columns extract date parts from Date and DateTime fields, with UTC conversion relevant for DateTime.
  • In code, use OPEN, Read and TopNumberOfRows to read the dataset, then get column values from the current row.
  • Queries give better performance and simpler code than record variables when joining multiple tables in codeunits.
  • Data analysis mode offers columns, filters, row groups, pivot mode, date hierarchies, fields from related tables, and bookmarks to the Role Center.

Learn pages

Videos and posts

Linked by a Haiku matcher with a grounding quote from the item’s summary (link/topics.ts); machine-generated.

Business Central pages and reports

The pages, reports and queries this hub’s Learn pages name (ms.search.form, API reference), joined to the code by exact object id (data/index/docs-objects.json); a page shows the table it runs on.

Source: Microsoft Learn (CC BY 4.0). Descriptions are Learn’s own.

What Learn documents here 8 of 9 Learn pages

Show 1 more