web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

SQL calls in a Query Objects

(2) ShareShare
ReportReport
Posted on by 37
Hi,
 
As far as I was aware, a query object would run one SQL call against the database and then iterate through the results. However, when looking at the telemetry it seems that an SQL call is happening every time the Query.Read is called. The KQL we are are using can be found below.
 
 
Below is the query object.
 
 dataitem(Vendor; Vendor)
        {
            column(No; "No.")
            {
            }
            column(Name; Name)
            {
            }
            column(Address; Address)
            {
            }
            column(Address2; "Address 2")
            {
            }
            column(City; City)
            {
            }
            column(County; County)
            {
            }
 
            dataitem(Item; Item)
            {
                DataItemLink = "Vendor No." = Vendor."No.";
                SqlJoinType = InnerJoin;
 
                column(ItemNo; "No.")
                {
                }
                column(Description; Description)
                {
                }
                column(SYCSize; "SYC Size")
                {
                }
                column(SYCPack; "SYC Pack")
                {
                }
                column(SYCCaseQuantity; "SYC Case Quantity")
                {
                }
                column(SYCLayerQuantity; "SYC Layer Quantity")
                {
                }
                column(SYCPalletQuantity; "SYC Pallet Quantity")
                {
                }
                column(SYCItemStatus; "SYC Item Status")
                {
                }
                column(Inventory; Inventory)
                {
                }
                column(QtyonSalesOrder; "Qty. on Sales Order")
                {
                }
                column(QtyonPurchOrder; "Qty. on Purch. Order")
                {
                }
                column(SYCSalesQtytoShip; "SYC Sales Qty. to Ship")
                {
                }
 
                column(UnitCost; "Unit Cost")
                {
                }
                column(SYCListCost; "SYC List Cost")
                {
                }
 
                dataitem(SYC_Sales_Analysis_History; "SYC Sales Analysis History")
                {
                    DataItemLink = "No." = Item."No.";
                    DataItemTableFilter = "Document Type" = const("Posted Sales Invoice");
                    SqlJoinType = InnerJoin;
                    column(Week_No_; "Week No.")
                    { }
 
                    column(Quantity; Quantity)
                    {
                        Method = Sum;
                    }
                    filter(Posting_Date; "Posting Date")
                    {
 
                    }
 
                }
            }
        }
I have the same question (0)
  • Verified answer
    Pallavi Phade Profile Picture
    4,399 on at
    Namaste @PaulJ94
     
    Below Microsoft Links support the explanation about how Query objects work and why each  Query.Read() fetches rows directly from SQL rather than executing one big SQL call and caching results
     
    Query Performance
     
    Query Read Function 
    This is the official link for the Query.Read() method — shows how Read() retrieves one row at a time from the dataset. 
     
    Query Hints 
     
    Query Object Overview
     
     
    Warm Regards
    Pallavi Phade
    www.linkedin.com/in/pallaviphade131116
     
  • PaulJ94 Profile Picture
    37 on at
    Hi Pallavi,
     
    Thanks for clarifying that.  The fields I have are a mixture of standard and bespoke fields meaning I can't combine them into one key. Would adding some of the fields to a key help at all or should I just use the Records instead of a query?
     
    Thanks,
    Paul
  • Verified answer
    OussamaSabbouh Profile Picture
    6,754 on at
    Hello ,
     
    Query.Read() does not mean “no more SQL”. BC can stream results from SQL, so seeing SQL activity per Read() is expected. In your case, the main reason is that the query includes FlowFields (e.g. Inventory, Qty. on Sales Order, Qty. on Purch. Order), which trigger extra SQL calculations while iterating. If you want near-single-SQL behavior, avoid FlowFields in queries and instead join/aggregate directly on the underlying entry tables or pre-aggregate the data.
     
    Regards,
    Oussama Sabbouh
  • Pallavi Phade Profile Picture
    4,399 on at
    Namaste @PaulJ94
     
    Is your query answered . 
     
    Regards
    Pallavi Phade

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,688

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 784 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 595 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans