# Sql query keep leading zero

**URL:** <https://forum.inductiveautomation.com/t/sql-query-keep-leading-zero/11089>\
**Category:** Ignition\
**Created:** [January 21, 2016, 8:12pm UTC](https://forum.inductiveautomation.com/t/sql-query-keep-leading-zero/11089 "2016-01-21T20:12:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [January 21, 2016, 8:12pm UTC](https://forum.inductiveautomation.com/t/sql-query-keep-leading-zero/11089/1 "2016-01-21T20:12:58Z")

</div>

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)

---

<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:** [January 21, 2016, 8:40pm UTC](https://forum.inductiveautomation.com/t/sql-query-keep-leading-zero/11089/2 "2016-01-21T20:40:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [January 21, 2016, 8:51pm UTC](https://forum.inductiveautomation.com/t/sql-query-keep-leading-zero/11089/3 "2016-01-21T20:51:25Z")

</div>

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

---

<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:** [January 21, 2016, 9:46pm UTC](https://forum.inductiveautomation.com/t/sql-query-keep-leading-zero/11089/4 "2016-01-21T21:46:29Z")

</div>

[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]
