# Issue trying coercing Meter ID value from Tag into SQL query

**URL:** <https://forum.inductiveautomation.com/t/issue-trying-coercing-meter-id-value-from-tag-into-sql-query/19400>\
**Category:** Ignition\
**Created:** [August 24, 2018, 8:55am UTC](https://forum.inductiveautomation.com/t/issue-trying-coercing-meter-id-value-from-tag-into-sql-query/19400 "2018-08-24T08:55:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1](https://avatars.discourse-cdn.com/v4/letter/u/5daacb/32.png) [@user1](https://forum.inductiveautomation.com/u/user1)\
**Post date:** [August 24, 2018, 8:55am UTC](https://forum.inductiveautomation.com/t/issue-trying-coercing-meter-id-value-from-tag-into-sql-query/19400/1 "2018-08-24T08:55:26Z")

</div>

Hey, I have a table is using a SQL query to fill in data. I want to post values filter on a meter id.

> SELECT [Meter id],  
> [pressbase],  
> [tempbase],  
> [sampletime]  
> FROM [eDB].[dbo].[efmconfig] WHERE [meter\_id] = **'XXX'** ORDER BY [sampletime] DESC

I've tried using an indirect tag on a Label, and Numeric Label (MeterID2)and then have the

> WHERE [meter\_id] = **'XXX'**

query use it to filter.

> WHERE [meter\_id] = **'{MeterID2.value}'**

I see that the correct Meter ID number shows on both labels I've tried, but the SQL query displays nothing. If I use the Database Query Browser and hardcode the meter id, it works. Any ideas what i'm missing? I saw someone had a similar issue with a Multi valve state, and the answer was to use an indirect tag. However that doesn't seem to be working for me. Your help is appreciated. Thanks

---

<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:** [August 24, 2018, 12:39pm UTC](https://forum.inductiveautomation.com/t/issue-trying-coercing-meter-id-value-from-tag-into-sql-query/19400/2 "2018-08-24T12:39:53Z")

</div>

When you string-embed a numeric into a raw SQL query, the generic string conversion will yield no leading zeroes or any other formatting. You are quoting the meter ID, so I presume it is a string in the DB. If so, use an intermediate custom property to format the number into a string in the expected way. If a numeric field in the DB, remove the quotes in your where clause to let the DB see it as a number.

---

<div class="post-metadata">

**Author:** ![user1](https://avatars.discourse-cdn.com/v4/letter/u/5daacb/32.png) [@user1](https://forum.inductiveautomation.com/u/user1)\
**Post date:** [August 24, 2018, 1:10pm UTC](https://forum.inductiveautomation.com/t/issue-trying-coercing-meter-id-value-from-tag-into-sql-query/19400/3 "2018-08-24T13:10:21Z")

</div>

> You are quoting the meter ID, so I presume it is a string in the DB

Yes, varchar(255)

> If so, use an intermediate custom property to format the number into a string in the expected way.

I'm not sure what this entails. Could you give a bit more details?
