# Named Query Inserting Inaccurate Decimal Value into DB

**URL:** <https://forum.inductiveautomation.com/t/named-query-inserting-inaccurate-decimal-value-into-db/70924>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [March 10, 2023, 7:09pm UTC](https://forum.inductiveautomation.com/t/named-query-inserting-inaccurate-decimal-value-into-db/70924 "2023-03-10T19:09:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [March 10, 2023, 7:09pm UTC](https://forum.inductiveautomation.com/t/named-query-inserting-inaccurate-decimal-value-into-db/70924/1 "2023-03-10T19:09:09Z")

</div>

I found something interesting today that I thought I'd share. I don't know if it's a bug or something I'm doing wrong/missing.

I was trying to insert a value from a perspective (8.1.18) numeric entry field into a database (MSSQL server 2019), with data type of decimal(14, 4). When I created a Named Query and sent the value to the query as a parameter (float4) I would get inaccurate decimal value in database. For example, if I entered 123.2 into the numeric entry field and called the named query, using `system.db.runNamedQuery`, to insert the value into the database. The value in the DB would be 123.2002 or maybe even 123.1998.

I tried running the same query using `runPrepUpdate` in the script and this saves an accurate decimal value of 123.2000 in the database.

It's a simple insert query  
`system.db.runPrepUpdate("INSERT INTO Table (vId, quantity) VALUES (?,?)", [myId,MyQty])`

Am I missing something? I'd prefer to use named queries so I can call it from multiple scripts.

---

<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:** [March 11, 2023, 12:00pm UTC](https://forum.inductiveautomation.com/t/named-query-inserting-inaccurate-decimal-value-into-db/70924/2 "2023-03-11T12:00:32Z")

</div>

> [@dkylep](#):
>
> query as a parameter (float4)

That's the problem. You are asking for seven significant digits from a format that can't do that. Use float8. It works in the prep query because jython (2.7) uses double for float values.

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [March 11, 2023, 8:06pm UTC](https://forum.inductiveautomation.com/t/named-query-inserting-inaccurate-decimal-value-into-db/70924/3 "2023-03-11T20:06:01Z")

</div>

Thank you!
