Sql query keep leading zero

I am having an issue where my leading zeros keep getting cut off of my string when i do my query.

[code]qv1 = event.source.parent.getComponent(‘Bushings’).text
qv2 = event.source.parent.getComponent(‘Adhesive’).text
qv3 = event.source.parent.getComponent(“Label 15”).text
qv4 = event.source.parent.getComponent(‘Container’).text
qv5 = event.source.parent.getComponent(‘Label 2’).fillBackground
qv6 = event.source.parent.getComponent(‘Label 10’).text

print "variables "
print qv1
print qv2
print qv3
print qv4

if len(qv1) >= 6 and len(qv2) >= 6 and len(qv3) >= 6 and len(qv4) >= 6 and qv5 == 0 and len(qv6) >= 3:
system.db.runUpdateQuery("INSERT INTO Thermoplastics.dbo.CureLot "
+ “(BushingsContainer, AdhesiveContainer, Container, CureLot, Operator) VALUES (%s, %s, %s, %s, %s)” %(qv1, qv2, qv4, qv3, qv6))

value = "0"
system.tag.write('Finishing/Bushings/Container', value)[/code]

Here is what prints

variables
0517980
0518077
160119092924
0

But what is when i look at my database I don’t see the leading zeros. All of the data types are varchar(30)

Your database is cutting off the leading zeros, not Ignition. You need to quote your string values inside the SQL statement, or use a runPrepUpdate() and let JDBC handle the quoting.

How do I quote the string values in the SQL statement?

[quote=“boster281”]How do I quote the string values in the SQL statement?[/quote]Like so:[code]system.db.runUpdateQuery("INSERT INTO Thermoplastics.dbo.CureLot "

  • “(BushingsContainer, AdhesiveContainer, Container, CureLot, Operator) VALUES (’%s’, ‘%s’, ‘%s’, ‘%s’, ‘%s’)” % (qv1, qv2, qv4, qv3, qv6))[/code]Or use parameters like so:[code]system.db.runPrepUpdate("INSERT INTO Thermoplastics.dbo.CureLot "
  • “(BushingsContainer, AdhesiveContainer, Container, CureLot, Operator) VALUES (?, ?, ?, ?, ?)”, [qv1, qv2, qv4, qv3, qv6])[/code]