# Gateway Script to get data into dataset

**URL:** <https://forum.inductiveautomation.com/t/gateway-script-to-get-data-into-dataset/56813>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [March 3, 2022, 11:35pm UTC](https://forum.inductiveautomation.com/t/gateway-script-to-get-data-into-dataset/56813 "2022-03-03T23:35:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mandeep\_gill](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mandeep\_gill](https://forum.inductiveautomation.com/u/mandeep_gill)\
**Post date:** [March 3, 2022, 11:35pm UTC](https://forum.inductiveautomation.com/t/gateway-script-to-get-data-into-dataset/56813/1 "2022-03-03T23:35:36Z")

</div>

I am currently using ignition Vision version 8.1.14 and OS windows server 2019.  
I have configure tags for history there are around 10 tags.  
I have to create a xml file everyday at 12:am for last day with reading of 30mins interval.

What is the best way to set this up.  
I was exploring the options to create a gateway script to call for name query( MSSQL) and then get data into dataset and converted into pydataset for creating xml file with custom xml schema. I am experiencing issue with Name query with database field t\_stamp fields which required to be converted into datatime format doesn’t appear to be easy way to convert this.  
I am not sure if i am going correct path or is there any other way to deal with this.

---

<div class="post-metadata">

**Author:** ![kvane](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kvane/32/22228_2.png) [@kvane](https://forum.inductiveautomation.com/u/kvane)\
**Post date:** [March 4, 2022, 12:32am UTC](https://forum.inductiveautomation.com/t/gateway-script-to-get-data-into-dataset/56813/2 "2022-03-04T00:32:23Z")

</div>

The t\_stamp field for tag history stores the milliseconds since epoch. MSSQL does have a method to parse out that value as a date. Take a look at this Knowledge Base Article: [Understanding Tag Historian Timestamps](https://support.inductiveautomation.com/hc/en-us/articles/360047136252-SQLTag-Historian-Timestamps).

I think your approach of going from dataset \> pydataset \> xml is fine. I would recommend you look at this function as well: [system.tag.queryTagHistory()](https://docs.inductiveautomation.com/display/DOC81/system.tag.queryTagHistory).

This function will likely be easier to utilize than writing out a manual query against the tag history tables.

---

<div class="post-metadata">

**Author:** ![mandeep\_gill](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mandeep\_gill](https://forum.inductiveautomation.com/u/mandeep_gill)\
**Post date:** [March 6, 2022, 6:05pm UTC](https://forum.inductiveautomation.com/t/gateway-script-to-get-data-into-dataset/56813/3 "2022-03-06T18:05:19Z")

</div>

Thanks Kvane,  
I manage to get the data using system.tag.queryhistory. this approch was easier than SQL name query.
