# How does ignition execute queries in report scripting

**URL:** <https://forum.inductiveautomation.com/t/how-does-ignition-execute-queries-in-report-scripting/107881>\
**Category:** Ignition\
**Tags:** scripting, reporting\
**Created:** [June 27, 2025, 1:39pm UTC](https://forum.inductiveautomation.com/t/how-does-ignition-execute-queries-in-report-scripting/107881 "2025-06-27T13:39:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikolai\_Eskild\_Jense](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@Nikolai\_Eskild\_Jense](https://forum.inductiveautomation.com/u/Nikolai_Eskild_Jense)\
**Post date:** [June 27, 2025, 1:39pm UTC](https://forum.inductiveautomation.com/t/how-does-ignition-execute-queries-in-report-scripting/107881/1 "2025-06-27T13:39:50Z")

</div>

Lets say i have a report with a scripting data source and to parameters StartDate and EndDate, which are dates

At some point in the data source i assign a data key

data['QueriedData']=system.db.runNamedQuery('named\_query'{"startDate":data['StartDate'],"endDate":data['EndDate'],})

Is the query then called each time i use @QueriedData@ in my report?  
Is it called if i never use @QueriedData@ in the report?

* * *

The reason i am asking is because I want to run a lot of queries against the table with different startdates. But i am unsure if that means that I will be calling all the queries each time i assign @QueriedData@. See example below

If condition: data['QueriedData']=system.db.runNamedQuery('named\_query'{"startDate":data['StartDate'],"endDate":data['EndDate'],})

Else:  
data[' **QueriedData2**']=system.db.runNamedQuery('named\_query'{"startDate2":data[' **StartDate2**'],"endDate":data['EndDate'],})

If i have a lot of permutations and large queries i want to be certain that i dont call them, when i dont need them. So if use @QueriedData@ in my report does QueriedData2 execute/Update

And if not, what if theres no _If condition_, but i only use @QueriedData@ in the report. Does it then call both queries?  
data['QueriedData']=system.db.runNamedQuery('named\_query'{"startDate":data['StartDate'],"endDate":data['EndDate'],})

data[' **QueriedData2**']=system.db.runNamedQuery('named\_query'{"startDate2":data[' **StartDate2**'],"endDate":data['EndDate'],})

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 27, 2025, 1:44pm UTC](https://forum.inductiveautomation.com/t/how-does-ignition-execute-queries-in-report-scripting/107881/2 "2025-06-27T13:44:57Z")

</div>

The report won't be generated at all until the script data source runs completely. It will only run once per report request. It will still run even if the report design doesn't use `@QueriedData@`. It won't run again even if you reference `@QueriedData@` multiple times.

It seems like you want scripted **nested** data. See this topic:

> [@Report with Scripted Nested Data](https://forum.inductiveautomation.com/t/report-with-scripted-nested-data/11801):
>
> The report datasource scripting examples explain how to access the nested data in another key for use constructing a custom dataset. What I don’t see is how to construct nested data that would be suitable for use with a child table in a table group. I have a parent dataset that I’m constructing via script due to annoying limitations of an ancient SQL Server 2000 instance. I need a subquery for each row that could be done with a normal query, but there’s no way to add a regular subquery to a s…
