# Problem with query from historical tag

**URL:** <https://forum.inductiveautomation.com/t/problem-with-query-from-historical-tag/33579>\
**Category:** Ignition\
**Created:** [April 1, 2020, 7:29am UTC](https://forum.inductiveautomation.com/t/problem-with-query-from-historical-tag/33579 "2020-04-01T07:29:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mitchel.Gommers](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@Mitchel.Gommers](https://forum.inductiveautomation.com/u/Mitchel.Gommers)\
**Post date:** [April 1, 2020, 7:29am UTC](https://forum.inductiveautomation.com/t/problem-with-query-from-historical-tag/33579/1 "2020-04-01T07:29:22Z")

</div>

Hello,

I am getting an error when i run a query. I want to visualize data from a historical tag in a Boxplot.  
I bind the query to the boxplot and i use a daterange for date selection. I dont see what its wrong in the query.

````auto
Where tagid = '22' and t_stamp between 

(DATEDIFF(s, '1970-01-01 00:00:00', {Root Container.Date Range.startDate} ) as bigint) * 1000) and (DATEDIFF(s, '1970-01-01 00:00:00', '{Root Container.Date Range.endDate}' ) as bigint) * 1000) ```
````

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [April 1, 2020, 8:13am UTC](https://forum.inductiveautomation.com/t/problem-with-query-from-historical-tag/33579/2 "2020-04-01T08:13:56Z")

</div>

You have a single quote round your end date but not your start date. Check that

---

<div class="post-metadata">

**Author:** ![Mitchel.Gommers](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@Mitchel.Gommers](https://forum.inductiveautomation.com/u/Mitchel.Gommers)\
**Post date:** [April 1, 2020, 9:11am UTC](https://forum.inductiveautomation.com/t/problem-with-query-from-historical-tag/33579/3 "2020-04-01T09:11:25Z")

</div>

I have tried a little and it is working now. Thanks for the reaction.

the right query is

````auto
SELECT intvalue FROM sqlt_data_1_2020_04
Where tagid = '22' and t_stamp between

CAST(Datediff(s, '1970-01-01','{Root Container.Date Range.startDate}') AS BIGINT) *1000
and
CAST(Datediff(s, '1970-01-01','{Root Container.Date Range.endDate}') AS BIGINT) *1000 ```
````
