# Access one piece of Data from Query Tag

**URL:** <https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [December 16, 2022, 9:19pm UTC](https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740 "2022-12-16T21:19:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason.schwenk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jason.schwenk/32/18822_2.png) [@jason.schwenk](https://forum.inductiveautomation.com/u/jason.schwenk)\
**Post date:** [December 16, 2022, 9:19pm UTC](https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740/1 "2022-12-16T21:19:13Z")

</div>

So here is the code I have so far....

```auto
Product_Code_Query = system.tag.read("[default]Product code Query Tag.value")
Product_Code_Compare = system.tag.read("[default]Product_Code_Compare_Tag.value")

print Product_Code_Query
print Product_Code_Compare

if (Product_Code_Query != Product_Code_Compare):
	system.tag.write("[default]Product_Code_Compare_Tag",Product_Code_Query.value)
	CurrentCount = system.tag.read("[default]L2_Former_Run_Day_Count")
	system.tag.write("[default]L2_Former_Run_Day_Count", (CurrentCount.value + 1))

```

I think it will do what I need it to but the issue is I cant seem to be able to access the specific data of the dataset.  
The "Product code Query Tag" is an SQL query tag that pulls the last entry into a database containing a date and a product code. The product code isnt run but once every few days so i am trying to keep a tally of how many days a particular product code is run and therefore be able to alarm on x amount of days to trigger a PM  
When I run the script I cant seem to pull out just the day and time to compare to see if it is a new day and increase the counter.  
Here is the output

```auto
>>> 
[Dataset [1R ? 2C], Good, Fri Dec 16 16:14:42 EST 2022]
[Dataset [1R ? 2C], Good, Fri Dec 16 16:14:58 EST 2022]
2
2
>>>

```

If I create a null value the values are different and it will copy the data over and increase the counter but it is comapring the entire dataset not the date. I have tried a million ways to parse just the date to compare but no luck!!  
Here is the data in the dataset I am querying  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/0/90bc6c35d33f2e2eddad2aa8e83b5a3e37d55cd4.png)  
Please Help I dont have any more hair to pull!!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 16, 2022, 10:30pm UTC](https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740/2 "2022-12-16T22:30:33Z")

</div>

If you're dealing with a dataset, you need to extract the particular value you care about, by providing a row index and column name or index:

```python
Product_Code_Query_DS = system.tag.read("[default]Product code Query Tag.value").value
Product_Code_Compare_DS = system.tag.read("[default]Product_Code_Compare_Tag.value").value

Product_Code_Query = Product_Code_Query_DS.getValueAt(0, "Date")
Product_Code_Compare = Product_Code_Compare_DS.getValueAt(0, "Date")

print Product_Code_Query_DS
print Product_Code_Query

print Product_Code_Compare_DS
print Product_Code_Compare

if Product_Code_Query != Product_Code_Compare:
	system.tag.write("[default]Product_Code_Compare_Tag",Product_Code_Query)
	CurrentCount = system.tag.read("[default]L2_Former_Run_Day_Count").value
	system.tag.write("[default]L2_Former_Run_Day_Count", CurrentCount + 1)

```

See the [Datasets](https://docs.inductiveautomation.com/display/DOC81/Datasets) reference page in the manual.

---

<div class="post-metadata">

**Author:** ![jason.schwenk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jason.schwenk/32/18822_2.png) [@jason.schwenk](https://forum.inductiveautomation.com/u/jason.schwenk)\
**Post date:** [December 16, 2022, 10:37pm UTC](https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740/3 "2022-12-16T22:37:04Z")

</div>

That what I figured but I Tried that before also.  
Here is the result of that code on my end

> > >

Traceback (most recent call last):  
File "", line 4, in   
AttributeError: 'com.inductiveautomation.ignition.common.sqltags.Ba' object has no attribute 'getValueAt'

> > >

What was executed  
Product\_Code\_Query\_DS = system.tag.read("[default]Product code Query Tag.value")  
Product\_Code\_Compare\_DS = system.tag.read("[default]Product\_Code\_Compare\_Tag.value")

Product\_Code\_Query = Product\_Code\_Query\_DS.getValueAt(0, 0)  
Product\_Code\_Compare = Product\_Code\_Compare\_DS.getValueAt(0, 0)

print Product\_Code\_Query  
print Product\_Code\_Query\_DS

print Product\_Code\_Compare  
print Product\_Code\_Compare\_DS

if (Product\_Code\_Query != Product\_Code\_Compare):  
system.tag.write("[default]Product\_Code\_Compare\_Tag",Product\_Code\_Query.value)  
CurrentCount = system.tag.read("[default]L2\_Former\_Run\_Day\_Count")  
system.tag.write("[default]L2\_Former\_Run\_Day\_Count", (CurrentCount.value + 1))

---

<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:** [December 16, 2022, 10:57pm UTC](https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740/4 "2022-12-16T22:57:12Z")

</div>

You are putting the `.value` inside the tagpath. Where it is redundant. The tag read call is still going to give you a `QualifiedValue` **object** , to which you can then apply `.value` to get the actual tag value.

---

<div class="post-metadata">

**Author:** ![jason.schwenk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jason.schwenk/32/18822_2.png) [@jason.schwenk](https://forum.inductiveautomation.com/u/jason.schwenk)\
**Post date:** [December 16, 2022, 11:07pm UTC](https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740/5 "2022-12-16T23:07:52Z")

</div>

Tried that also  
It doesnt give me the data though only gives me the Dataset? It also doesnt see them as equal and increments which is what led me to try and just isolate the date since it would be the only thing that changes.  
Here is the output I get now

> > >

Dataset [1R ? 2C]  
[Dataset [1R ? 2C], Good, Fri Dec 16 16:14:42 EST 2022]  
Dataset [1R ? 2C]  
[Dataset [1R ? 2C], Good, Fri Dec 16 18:04:32 EST 2022]  
2  
2

> > >

And the code

Product\_Code\_Query\_DS = system.tag.read("[default]Product code Query Tag")  
Product\_Code\_Compare\_DS = system.tag.read("[default]Product\_Code\_Compare\_Tag")

Product\_Code\_Query = Product\_Code\_Query\_DS.value  
Product\_Code\_Compare = Product\_Code\_Compare\_DS.value

print Product\_Code\_Query  
print Product\_Code\_Query\_DS

print Product\_Code\_Compare  
print Product\_Code\_Compare\_DS

if (Product\_Code\_Query != Product\_Code\_Compare):  
system.tag.write("[default]Product\_Code\_Compare\_Tag",Product\_Code\_Query)  
CurrentCount = system.tag.read("[default]L2\_Former\_Run\_Day\_Count")  
system.tag.write("[default]L2\_Former\_Run\_Day\_Count", (CurrentCount.value + 1))

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 16, 2022, 11:13pm UTC](https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740/6 "2022-12-16T23:13:09Z")

</div>

You need to do _both_ things, as I did in my code above.

Use `.value` to go from the BasicQualifiedValue returned by `system.tag.read` to a Dataset.  
Then use `.getValueAt(row, column)` to get a single scalar value out of that dataset.  
You **must** do both.

---

<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:** [December 16, 2022, 11:24pm UTC](https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740/7 "2022-12-16T23:24:30Z")

</div>

{ When you paste code or error tracebacks, please use the "Preformatted Text" button (\</\>) to make them look right. Help us help you. }

---

<div class="post-metadata">

**Author:** ![jason.schwenk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jason.schwenk/32/18822_2.png) [@jason.schwenk](https://forum.inductiveautomation.com/u/jason.schwenk)\
**Post date:** [December 18, 2022, 10:58am UTC](https://forum.inductiveautomation.com/t/access-one-piece-of-data-from-query-tag/67740/8 "2022-12-18T10:58:06Z")

</div>

> [@paul-griffith](#):
>
> ```auto
> Product_Code_Query_DS = system.tag.read("[default]Product code Query Tag.value").value
> Product_Code_Compare_DS = system.tag.read("[default]Product_Code_Compare_Tag.value").value
> 
> Product_Code_Query = Product_Code_Query_DS.getValueAt(0, "Date")
> Product_Code_Compare = Product_Code_Compare_DS.getValueAt(0, "Date")
> 
> ```

AH HA!!!!!  
I didnt scroll over and see the .value at the end of the first 2 lines!  
IT WORKED THANK YOU!!!!!!
