# SQL Tag Event script

**URL:** <https://forum.inductiveautomation.com/t/sql-tag-event-script/16907>\
**Category:** Ignition\
**Tags:** database, scripting\
**Created:** [February 7, 2018, 2:32pm UTC](https://forum.inductiveautomation.com/t/sql-tag-event-script/16907 "2018-02-07T14:32:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julio.Bautista](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Julio.Bautista](https://forum.inductiveautomation.com/u/Julio.Bautista)\
**Post date:** [February 7, 2018, 2:32pm UTC](https://forum.inductiveautomation.com/t/sql-tag-event-script/16907/1 "2018-02-07T14:32:16Z")

</div>

I have a SQL tag query that looks at a table constructed by a transaction group.  
The following is my query in which is saved to the tag as a dataset  
SELECT top 2 DateTime from Cast\_Time order by DateTime desc

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c9c51ede0beb4fd0d9e22bf98939c77ca6b6e091.png)  
The script doesn’t seem to launch. is it because ignition isn’t looking directly at the values in the dataset? If so what datatype would be best to save two datetime values from sql into.

I want to be able to write this value onto a memory tag so that for all the clients can have the correct time being displayed

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [February 7, 2018, 2:34pm UTC](https://forum.inductiveautomation.com/t/sql-tag-event-script/16907/2 "2018-02-07T14:34:39Z")

</div>

On line 9 remove the indentation. Your function call is inside the function.

---

<div class="post-metadata">

**Author:** ![Julio.Bautista](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Julio.Bautista](https://forum.inductiveautomation.com/u/Julio.Bautista)\
**Post date:** [February 7, 2018, 2:48pm UTC](https://forum.inductiveautomation.com/t/sql-tag-event-script/16907/3 "2018-02-07T14:48:35Z")

</div>

I didn’t notice that thank you.  
quick question would I be able to incase line 9 within a if statement that looks at another tag’s Boolean value?

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [February 7, 2018, 3:03pm UTC](https://forum.inductiveautomation.com/t/sql-tag-event-script/16907/4 "2018-02-07T15:03:49Z")

</div>

Should be no problem. You could use system.tag.read(your\_tag\_path) to read the value of the tag and then proceed according to its value.

```auto
tagValue = system.tag.read(some_tag_path).value
if tagValue:
    system.util.invokeLater(DatabaseQuery, 5000)

```
