Error The coversion from UNKNOWN to UNKNOWN is unsupported

hello

I have the following problem with a script.

caused by Exception: Error executing system.db.runPrepUpdate(INSERT INTO PAROS (Linea, Maquina, TipoParo, TiempoParo, Fecha) VALUES (?, ?, ?, ?, ?), [Linea_ED, [57, Good, Thu Oct 21 05:44:28 CDT 2021], [4, Good, Thu Oct 21 05:44:28 CDT 2021], [11, Good, Tue Nov 02 08:18:59 CST 2021], Tue Nov 02 08:19:01 CST 2021], TOPY_MW, , false, false)
caused by GatewayException: SQL error for INSERT INTO PAROS (Linea, Maquina, TipoParo, TiempoParo, Fecha) VALUES (?, ?, ?, ?, ?): The conversion from UNKNOWN to UNKNOWN is unsupported.
caused by SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported.

image

the variable called “TiempoParo” I get it from a Tag of type datetime since in my sql table it is of type time.

It looks like you are reading the tags then trying to insert their values into the database. Tag reads are fully qualified meaning a read will return the tag value state, the time stamp, and the value. To get just the value you would need something like

tags = ['tag1','tag2']
results = system.tag.readBlocking(tags)
tagValueOne = results[0].value
tagValueTwo = results[1].value
1 Like

I think it’s because of the type of data I want to store because in my database time.

I have already made some modifications in the code but now I have another problem.

INS = "INSERT INTO PAROS (Linea, Maquina, TipoParo, TiempoParo, Fecha) VALUES (?, ?, ?, ?, ?)"
Maquina = system.tag.read("Botones/Linea_ED/Conteo Falla ED/Maquina")
Tipo = system.tag.read("Botones/Linea_ED/Conteo Falla ED/Tipo_Falla")

Tiempo = system.tag.read("OEE/LINEA_ED/captura manual ED").value

Contador = system.date.midnight(system.date.now())
print "Contador=", Contador
Contador = system.date.addMinutes(Contador, Tiempo)
print "Contador=", Contador 
Contador = system.date.format(Contador, "HH:mm:ss")
print "Contador=", Contador
system.util.getLogger("TimeContador").info(str(Contador))




Fecha = system.date.now()
VAL = ['Linea_ED', Maquina.value, Tipo.value, Contador.value, Fecha]
system.db.runPrepUpdate(INS,VAL,"TOPY_MW")

The error message is telling you exactly what the problem is, the second arg isn’t an integer. This should be referring to this line

Contador = system.date.addMinutes(Contador, Tiempo)

I bet if you print the type it will be a string.

print type(Tiempo)

Change the tag type to integer, if possible, or cast the read value

int(Tiempo)