SQL null value Tag value change eventq

I’m having an issue with a change event triggering when the SQL sends a null Value

This is my SQL call

Select isnull(ps.OrderNumber,0) 
FROM DAL.dc.vCurrentPressStatus ps
where Press = 'RC805'
This is my Value Changed Code
	if initialChange == 0:
		if currentValue.value != 0:
			if previousValue.value != currentValue.value:
				system.tag.write("[]Presses/RCS805/Job Changed to Martin",1)
				CT = system.tag.read("[System]Gateway/CurrentDateTime")
				system.tag.write("[.]JobStarttime",CT.value)

Ignition 7.8.2

So if the operator logs off the value goes null then when the next operator logs in the value comes back. I reset a couple of counters on the Job number change. If the value is still the same when the new operator comes in I don’t want to run the code.

Sorry, I’m trying to get a feel for what you want, but it seems likes there’s a chunk of information missing right now.

Is the SQL query being done inside a query tag or somewhere else?

Do you want the value to go to null when the operator logs off? What you really care about is if the value has changed right?

The SQL query is being done inside a query tag, and yes all I care about is if the value has change.

The value goes null when the operator logs off of a PMRS system where I get the SQL information from, I have no control over this action.

Okay, so the query is supposed to return a 0 if it encounters a null value (which it should when the user logs off) and that is stored in a tag which I’m guessing is “currentValue”

Then you have second bit of code (stored in a client or gateway script I’m guessing?) which is supposed to trigger provided currentValue is not 0 and the previous value is different than the current value.

But for some reason the code is executing even when query is NULL which means it should return zero…

Is currentValue a float/double? It’s possible that due to some funny floating point math the number being returned isn’t quite zero.

You could try doing something like

[code]
import math

if initialChange == 0:
if math.floor(currentValue.value) != 0:
if previousValue.value != currentValue.value:
system.tag.write("[]Presses/RCS805/Job Changed to Martin",1)
CT = system.tag.read("[System]Gateway/CurrentDateTime")
system.tag.write("[.]JobStarttime",CT.value)[/code]

Otherwise you could create a second query tag, let’s call it “queryActive” that’s a boolean with the same query code. Then create a custom scan class and set the mode to “driven” using the “queryActive” tag you just made as the driving tag.

Then you could change the scan class of currentValue to the new scan class you just made and change your code to:

if initialChange == 0: if previousValue.value != currentValue.value: system.tag.write("[]Presses/RCS805/Job Changed to Martin",1) CT = system.tag.read("[System]Gateway/CurrentDateTime") system.tag.write("[.]JobStarttime",CT.value)

Since currentValue will only update provided the query is not null.

Hope that’s helpful and I’m not suggesting things you’ve already tried :laughing:

Reading through your answer I think i stumbled on my issue, I have the tag as a string changed it to an integer and i think my issues have gone away. I knew it would be something dumb… Thanks for the help