# Data displayed null value while run sql query for the report format

**URL:** <https://forum.inductiveautomation.com/t/data-displayed-null-value-while-run-sql-query-for-the-report-format/97499>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [October 19, 2024, 7:02am UTC](https://forum.inductiveautomation.com/t/data-displayed-null-value-while-run-sql-query-for-the-report-format/97499 "2024-10-19T07:02:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Govind\_Suthar1](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Govind\_Suthar1](https://forum.inductiveautomation.com/u/Govind_Suthar1)\
**Post date:** [October 19, 2024, 7:02am UTC](https://forum.inductiveautomation.com/t/data-displayed-null-value-while-run-sql-query-for-the-report-format/97499/1 "2024-10-19T07:02:55Z")

</div>

Hii All,

Faced issue while preview of report data,it's showing null value.

Configured a SQL query for the report format. This query for the calculate total machine working hours during 24 hour cycle.

Problem: As per mentioned below query for fetch total hours without defining the parameter. (Like a StartDate, EndDate) The data is displayed in the output window.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/5/553615dad7bba46787474c2835954eca5a1af740.png)

Configure a SQL query as per below.

```python
SELECT Min(sqlt_data_2_2024_10.intvalue) AS Min_intvalue,
  Max(sqlt_data_2_2024_10.intvalue) AS Max_intvalue,
  Max(sqlt_data_2_2024_10.intvalue) - Min(sqlt_data_2_2024_10.intvalue) AS
  Total_Hour
FROM sqlt_data_2_2024_10
WHERE sqlt_data_2_2024_10.tagid = 889

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/6/f60a4002b3d0cfca49b62b9c73d5f609bd0b9eb2.png)

Defined the query data.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/9/89885b4ddbf3d95111ef36619e2aacb796af028d.png)

But, when defined a StartDate and EndDate parameter, displayed data a null value.

```python
SELECT Min(sqlt_data_2_2024_10.intvalue) AS Min_intvalue,
  Max(sqlt_data_2_2024_10.intvalue) AS Max_intvalue,
  Max(sqlt_data_2_2024_10.intvalue) - Min(sqlt_data_2_2024_10.intvalue) AS
  Total_Hour
FROM sqlt_data_2_2024_10
WHERE sqlt_data_2_2024_10.tagid = 889 AND t_stamp BETWEEN ? AND ?

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/7/f7c35d406736725258c093db3918b30461aecbb0.png)

---

<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:** [October 19, 2024, 3:19pm UTC](https://forum.inductiveautomation.com/t/data-displayed-null-value-while-run-sql-query-for-the-report-format/97499/2 "2024-10-19T15:19:02Z")

</div>

You are directly querying the historian's SQL tables. Don't do this. While their current architecture is documented, it is not guaranteed to not change and is unsupported. Use `system.tag.queryTagHistory()`. It will handle datetime conversions for you and will union data partitions as needed.

---

<div class="post-metadata">

**Author:** ![Govind\_Suthar1](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Govind\_Suthar1](https://forum.inductiveautomation.com/u/Govind_Suthar1)\
**Post date:** [October 21, 2024, 9:52am UTC](https://forum.inductiveautomation.com/t/data-displayed-null-value-while-run-sql-query-for-the-report-format/97499/3 "2024-10-21T09:52:48Z")

</div>

` system.tag.queryTagHistory()`  
How implement above query in a report format?

Can you give example for better understanding?

---

<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:** [October 21, 2024, 12:49pm UTC](https://forum.inductiveautomation.com/t/data-displayed-null-value-while-run-sql-query-for-the-report-format/97499/4 "2024-10-21T12:49:58Z")

</div>

In a report, use a tag historian data source--it takes the same arguments that the scripting function expects.

> **[Tag Historian Query | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/reporting/report-data/tag-historian-query)**
>
> The Tag Historian Query provides a simple way to query data from Tag Historians. In the Tag History Query you can read data from Historical Tags for specific date ranges, apply aggregates, and specify the sample size. It functions the same as a Tag...

---

<div class="post-metadata">

**Author:** ![Govind\_Suthar1](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Govind\_Suthar1](https://forum.inductiveautomation.com/u/Govind_Suthar1)\
**Post date:** [October 22, 2024, 12:53pm UTC](https://forum.inductiveautomation.com/t/data-displayed-null-value-while-run-sql-query-for-the-report-format/97499/5 "2024-10-22T12:53:39Z")

</div>

> [@pturmel](#):
>
> In a report, use a tag historian data source--it takes the same argum

Thank you for reply,

Yes, it worked, implemented a tag calculation query to count the various aggregate functions.
