# Report Tag Historian Query ( Start Date and End Date )

**URL:** <https://forum.inductiveautomation.com/t/report-tag-historian-query-start-date-and-end-date/58799>\
**Category:** Ignition\
**Created:** [April 25, 2022, 7:30am UTC](https://forum.inductiveautomation.com/t/report-tag-historian-query-start-date-and-end-date/58799 "2022-04-25T07:30:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gediminas.labutis](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gediminas.labutis](https://forum.inductiveautomation.com/u/gediminas.labutis)\
**Post date:** [April 25, 2022, 7:30am UTC](https://forum.inductiveautomation.com/t/report-tag-historian-query-start-date-and-end-date/58799/1 "2022-04-25T07:30:39Z")

</div>

We have a report where all data is retrieved by using named query - operator has to supply batch number and then SQL query reads required data. Among retrieved data we have batch start time and batch end time. I would like to use these as a start/end date binding for a tag history query in the same report (for timeseries chart). But tag history query only accepts report parameters for start/end date binding.  
How do I get query data to parameters ? Can I use the script to write directly to report parameters, or should I write to tags then bind parameters to tags ? Or write directly to chart object parameters ?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4ed36ee2470ad0c47948d516b4c8f9469d1b31cf.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 25, 2022, 7:38am UTC](https://forum.inductiveautomation.com/t/report-tag-historian-query-start-date-and-end-date/58799/2 "2022-04-25T07:38:06Z")

</div>

Vision or Perspective? (Add a tag to your question.)

For Vision you could store the timestamps in client tags.  
For Perspective you could store the timestamps in session variables.

You can then bind the start and end dates to those variables.

---

<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:** [April 25, 2022, 1:13pm UTC](https://forum.inductiveautomation.com/t/report-tag-historian-query-start-date-and-end-date/58799/3 "2022-04-25T13:13:21Z")

</div>

{ It is not strictly Vision or Perspective. It is a Report. }

If you have only one returned row for your Batch information, you could use a script data source to obtain those fields and save them in the `data` dictionary as stand-alone parameters.

However, it is probably visually easier to simply make a nested query–the nested query can use outer field names as parameters.

---

<div class="post-metadata">

**Author:** ![gediminas.labutis](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gediminas.labutis](https://forum.inductiveautomation.com/u/gediminas.labutis)\
**Post date:** [April 25, 2022, 5:05pm UTC](https://forum.inductiveautomation.com/t/report-tag-historian-query-start-date-and-end-date/58799/4 "2022-04-25T17:05:37Z")

</div>

My chart parameters and data sources  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/d/3d5d806c857deb347487d76e66ab2c28105e60fd.png)

I can bind start/end date only to parameter - not directly to tag or to data key  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/9/d912a8bb2207545232f8590d2d02083c7c8e464e.png)

And parameter can only by connected to tag.

I have tried following:

- writing to parameters does not work, or maybe I am writing to them incorrectly
- data keys are not accessible for binding directly to range in tag history query or to parameters
- writing to tags and binding parameters to tags (and then tag history query range to parameters) kind of work, except that tags updates AFTER batch report is executed and trend data range is from previously executed report.

```auto
	# Write to parameters
	ChartStartDT = rawDataset.getValueAt(0,'BATCH_START_DT_TREND')
	ChartEndEndDT = rawDataset.getValueAt(0,'BATCH_END_DT_TREND')
	
	# Write to data keys
	data['TrendStart'] = rawDataset.getValueAt(0,'BATCH_START_DT_TREND')
	data['TrendEnd'] = rawDataset.getValueAt(0,'BATCH_END_DT_TREND')	
	
	# Write to tags
	system.tag.writeBlocking ("[MX01]REPORTING/SF_BR_TREND_START_DT",rawDataset.getValueAt(0,'BATCH_START_DT_TREND'))
	system.tag.writeBlocking ("[MX01]REPORTING/SF_BR_TREND_END_DT",rawDataset.getValueAt(0,'BATCH_END_DT_TREND'))

```

So I guess I will have to supply tag history range to parameters before executing report.  
Not a big issue, I was just hoping to do that from report itself.

---

<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:** [April 25, 2022, 7:03pm UTC](https://forum.inductiveautomation.com/t/report-tag-historian-query-start-date-and-end-date/58799/5 "2022-04-25T19:03:44Z")

</div>

Click on your br\_query. Then, over on the right hand side of the designer, create your tag\_history query as a **nested** query **under** the br\_query.

---

<div class="post-metadata">

**Author:** ![gediminas.labutis](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gediminas.labutis](https://forum.inductiveautomation.com/u/gediminas.labutis)\
**Post date:** [April 25, 2022, 7:24pm UTC](https://forum.inductiveautomation.com/t/report-tag-historian-query-start-date-and-end-date/58799/6 "2022-04-25T19:24:36Z")

</div>

Yes for SQL query but not for Tag Historian query ?
