Event driven query tags null

I have two tags that were set to value source query that are returning 'null'.
They are event driven.
Ignition 8.1.19

When I run the queries, I get the right values.

How do I make it so that those never say null again, or if they say null they check their value again?

Value Source: Query

When I run the queries, ...

When you run them where?

Checklist

  • Is the query returning a scaler value?
  • Is your Data Type set correctly for the returned value datatype?
1 Like

Datatype is integer for both the tag and column in the table.
The value returned is just the select top 1 myColumn from table where clause

Two things, the query had been working fine, never touched it in a long time.
Suddenly yesterday, I hear that a value was showing wrong on a screen.
I check today, value is null.

I run the query in the query browser, returns exactly the value I expect.
I check the tags used in the query, their values are correct.

I changed a value of an a memory tag used in the driven query, still query is null.
I set the tag to fixed rate, still value is null.
I run in the query browser, still get the correct value.

A query using the same query, except selecting a different column, is returning the correct value.


I plugged in numbers instead of tag reads on the query, immediately right value shows.

I put the tags references back into the query, and reads null again.

Now I am really confused. Suddenly the value is reading correctly.
I didn't even change anything.

But I need these values to always read correctly. I can't have this part of the time working. I am not sure how to make it robust.


I have three of these tags. They all use the same exact queries except different columns.

The one is reading the value correctly after I had removed the tag references, and put them back.
(speed per hour)

The second uses exactly the same query, except different column. It doesn't work.
(expected speed per hour)

The third is a string type, and never read wrong, still reads right.
(production type name string based on the data collected from the same tags)

I can't share an image of it. I think I need to do maybe a support call.

Are you using another tag as a parameter in a tag query or what?
Show your query syntax.

1 Like
select top 1 myFirstTagCorrectlyShowingNowInt from myTable
where thirdColumn = {[.]}aSpeedDataTag.value}
and fourthColum = case when thirdColumn =42 then {[.]aSecondSpeedDataTag.value} else 4 end
and production = 'B2'

select top 1 mySecondTagStillShowingNullInt from myTable
where thirdColumn = {[.]}aSpeedDataTag.value}
and fourthColum = case when thirdColumn =42 then {[.]aSecondSpeedDataTag.value} else 4 end
and production = 'B2'

select top 1 myThirdTagBeenShowingCorrecltyString from myTable
where thirdColumn = {[.]}aSpeedDataTag.value}
and fourthColum = case when thirdColumn =42 then {[.]aSecondSpeedDataTag.value} else 4 end
and production = 'B2'

The second and third query tags, I didn't change my tag references.
If I change the second one's tag references, like remove.
Apply
Then if I put the tag references back, I think it will work.

I think I need a better way though, this should have been working the whole time.

OMG

Someone, possibly me? added an 's' to the tag name.
Or removed an s from the tag name in the query.

If it happened yesterday, it was definitely not me.

Thanks for your patience and help @Transistor

You might as well fix the spelling here while you're at it!

1 Like

The average person makes 7 mistakes an hour. I probably make 8 an hour.

I am trying to do this sort of thing again.

The query tag value when set to sting type shows 1.

The query tag value set as a data type shows value as the column name.
There is a 1 in the value for that column.

I get an error if I try to use 'as name' in the select.

select top 1 {[.]partString
from mytable t1
left join secondTable t2 on 
t1.line=t2.line
where part like concat('%','1b2345', '%')
and location ='B1'

I think the issue is that the string for partString starts with a number.


PTurmel saved me again.
I needed to add quote marks.

select top 1 '{[.]partString'
from mytable t1
left join secondTable t2 on 
t1.line=t2.line
where part like concat('%','1b2345', '%')
and location ='B1'

Query tags aren't safe to use with strings, as there's no way to parameterize them properly (yet). You should use a named query in a timer script that writes its result to a memory tag.

1 Like

You mean that if I do something like:

select top 1 partNumber
from mytable t1
left join secondTable t2 on 
t1.line=t2.line
where sku like concat('%','{[.]skuString', '%')
and  ord like  concat('%','{[.]ordString', '%')
and location ='B1'

Then I will miss some query runs because the tag will not detect that the tags in the where clause updated?

Or do you mean something worse than missing the updates?

By safe, I mean "non-hackable". If a malicious source puts certain special characters into your strings, including an unexpected closing quote, severe damage to your DB can result.

Thanks

I was wondering if I could trust tags from the plc, but I probably can't trust the strings.


In my case, I will need to write an event script on my order tag and run a named query from a change event script.
Then I will write that.
I get the current order from my plc.