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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Invent Trans query object is very very slow, how execute faster

(2) ShareShare
ReportReport
Posted on by 6
I have created a SSRS report with DP class, to get data from invent Trans and created a query object with following code to get the data, but report take more than 1 hour to generate, that is not efficient at all, how to execute so that i can get results in max 5 min or so.
 Query query = new Query();               qbds = query.addDataSource(tableNum(InventTrans));        qbds.addRange(fieldNum(InventTrans, DatePhysical)).value(SysQuery::range(dateNull(),asOfDate));                qbds.addSortField(fieldNum(InventTrans, ItemId));        if(item)        {            qbds.addRange(fieldNum(InventTrans, ItemId)).value(item);        }        qbdsDim = qbds.addDataSource(tableNum(InventDim));                qbdsDim.relations(true);        if(inventSiteid)        {            qbdsDim.addRange(fieldNum(InventDim, InventSiteId)).value(inventSiteid);        }        if(inventLocationId)        {            qbdsDim.addRange(fieldNum(InventDim, InventLocationId)).value(inventLocationId);        }                QueryRun queryRun = new QueryRun(query);        int i;        while (queryRun.next())        {        ///Report Logic to get Data and insert in temporaray table        }
 
I have the same question (0)
  • Suggested answer
    Layan Jwei Profile Picture
    8,280 Super User 2026 Season 1 on at
    Hi Sachin,
     
    Maybe start by improving your query. For example, you can start by selecting only the fields you need from the query and not all of them.
     
    Also you need to identify if the query is the root cause for the slowness or not (which most probably is)
    You can do that by running the report with trace parser to see which part took the most time. 
    Also you can take the sql query and run in sql server management system and look at the execution plan to see which part is taking time and if u can improve it.
     
    After you improve the query, if it's still taking time and you don't think there is anything else you can improve in code, then you can make your RDP class extends SRSReportDataProviderPreProcessTempDB instead of SRSReportDataProviderBase
     
    Thanks,
    Layan Jweihan 
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future.
  • Martin Dráb Profile Picture
    240,077 Most Valuable Professional on at
    Please show us the actual query. We can't know what SQL query your code generated because it depends on some variables. It's even possible that the query fetches all inventory transactions in the given company, which may be a huge amount of data.
     
    Also, the fact that the report takes an hour to generate doesn't mean that this query is to blame. For example, a bigger problem may be in your code saving the data. You should analyze the situation, otherwise you may be wasting time with a wrong problem. I would start by debugging this code in isolation instead of doing it through the report.
  • Raj Borad Profile Picture
    1,578 on at
    Hi Sachin,
     
    can you please try below query to run in SSMS and check whether it improves the performance or not.
     
    select * from  inventTrans
        where inventTrans.DatePhysical >= dateNull()
           and inventTrans.DatePhysical <= asOfDate
           and ( !item || inventTrans.ItemId == item )
        join inventDim
            oninventDim.InventTransId == inventTrans.RecId
               and ( !inventSiteId || inventDim.InventSiteId == inventSiteId )
               and ( !inventLocationId || inventDim.InventLocationId == inventLocationId )
        order by inventTrans.ItemId
     
    Thank you,
    Raj D Borad
     
  • Waed Ayyad Profile Picture
    9,212 Super User 2026 Season 1 on at
    Hi,

    Reformatting your code for better understanding it. You should try to run your report without adding logic on the on While of the Query in order to define the source of the issue. If it is still taking a lot of time, then try to reduce your query data sources one by one to check which part is consuming a lot of time (has a lot of data).

    Query query = new Query();            
    qbds = query.addDataSource(tableNum(InventTrans));  
    qbds.addRange(fieldNum(InventTrans, DatePhysical)).value(SysQuery::range(dateNull(),asOfDate));                qbds.addSortField(fieldNum(InventTrans, ItemId));    
    
     if(item)   
     {   
        qbds.addRange(fieldNum(InventTrans, ItemId)).value(item);   
     }    
    
     qbdsDim = qbds.addDataSource(tableNum(InventDim));   
     qbdsDim.relations(true);
            
    if(inventSiteid) 
    {     
       qbdsDim.addRange(fieldNum(InventDim, InventSiteId)).value(inventSiteid);        
    }      
    
    if(inventLocationId)  
    {     
       qbdsDim.addRange(fieldNum(InventDim, InventLocationId)).value(inventLocationId);
    }      
             
     QueryRun queryRun = new QueryRun(query);  
     int i; 
     
     while (queryRun.next())
    {      
      ///Report Logic to get Data and insert in temporaray table     
    }
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue.
    ​​​​​​​

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

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 393 Super User 2026 Season 1

#2
Subra Profile Picture

Subra 385

#3
Martin Dráb Profile Picture

Martin Dráb 252 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans