# Update Query data set

**URL:** <https://forum.inductiveautomation.com/t/update-query-data-set/73171>\
**Category:** Ignition\
**Created:** [May 2, 2023, 11:19pm UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171 "2023-05-02T23:19:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![blueberry](https://avatars.discourse-cdn.com/v4/letter/b/54ee81/32.png) [@blueberry](https://forum.inductiveautomation.com/u/blueberry)\
**Post date:** [May 2, 2023, 11:19pm UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/1 "2023-05-02T23:19:53Z")

</div>

Hello folks,  
Could someone please help me out?  
I made an OPC tag and a Query data set. I would like to update the query data set values every time the OPC tag changes state. I do not know the syntax to trigger query data set to get new value.  
This is what i have for the OPC tag, the "then" part i do not know how to write  
if previousValue.value != currentValue.value and currentValue.value == 1

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [May 3, 2023, 3:07am UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/2 "2023-05-03T03:07:12Z")

</div>

Tag event script will help. CurrentValue and previousValue are already there.  
Then script what you want. 🙂

[https://docs.inductiveautomation.com/display/DOC81/Tag+Event+Scripts](https://docs.inductiveautomation.com/display/DOC81/Tag+Event+Scripts)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 3, 2023, 8:08am UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/3 "2023-05-03T08:08:21Z")

</div>

What do you mean by "query dataset" ?  
If it's a database table, then transaction groups are what you're looking for.

---

<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:** [May 3, 2023, 12:32pm UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/4 "2023-05-03T12:32:46Z")

</div>

It is a really bad idea to run DB queries in tag events (on the tag). The thread pool for tag events is easily bogged down by events that perform **any** complex operation (more than a millisecond or two), particularly operations that reach out to a network resource. The entire tag event system will grind to a halt if this happens. Don't do it.

---

<div class="post-metadata">

**Author:** ![blueberry](https://avatars.discourse-cdn.com/v4/letter/b/54ee81/32.png) [@blueberry](https://forum.inductiveautomation.com/u/blueberry)\
**Post date:** [May 3, 2023, 9:16pm UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/5 "2023-05-03T21:16:35Z")

</div>

I am already using tag event script.  
Yes, it is a database table but I thought transaction group always running and update itself. I only want to trigger the script to fill out my query tag when certain event comes true. And the syntax to fill out my query tag (dataset type, multiple values inside the tag) is where I am stuck.  
If using a tag event to trigger is bad... what are other solutions?

Thanks

---

<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:** [May 3, 2023, 10:30pm UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/6 "2023-05-03T22:30:18Z")

</div>

I recommend using a project's gateway tag change event instead of a tag's valueChange event for anything that might take more than single-digit milliseconds.

---

<div class="post-metadata">

**Author:** ![blueberry](https://avatars.discourse-cdn.com/v4/letter/b/54ee81/32.png) [@blueberry](https://forum.inductiveautomation.com/u/blueberry)\
**Post date:** [May 3, 2023, 11:01pm UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/7 "2023-05-03T23:01:58Z")

</div>

In that case, could you please help me out with the syntax? I've done single parameter query via gateway event before but I do not know how to write when the destination is a dataset and not a single value tag.

Thanks

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [May 4, 2023, 1:36am UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/8 "2023-05-04T01:36:16Z")

</div>

You have to be very detailed and very specific about the functions you want, your database structure, and how you want to modify which data.  
In addition, before operating the database, have you made a backup? What are you going to do if the results don't meet your expectations?

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [May 4, 2023, 1:36am UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/9 "2023-05-04T01:36:48Z")

</div>

May I ask, if the update speed of the PLC value is limited by the PLC program, does the execution time of the variable script matter? For example, a script of 10 seconds and an update rate of 1 minute.  
Thank you.

---

<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:** [May 4, 2023, 1:49am UTC](https://forum.inductiveautomation.com/t/update-query-data-set/73171/10 "2023-05-04T01:49:59Z")

</div>

Yes, because **all** of the tag event scripts are running in the same thread pool.
