# DB Tag Expression Error

**URL:** <https://forum.inductiveautomation.com/t/db-tag-expression-error/3502>\
**Category:** Ignition\
**Created:** [October 26, 2011, 10:02pm UTC](https://forum.inductiveautomation.com/t/db-tag-expression-error/3502 "2011-10-26T22:02:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [October 26, 2011, 10:02pm UTC](https://forum.inductiveautomation.com/t/db-tag-expression-error/3502/1 "2011-10-26T22:02:58Z")

</div>

I have setup many alert tags with this expression:

```auto
if(dateDiff(toDate(executeScalarQuery("SELECT TOP 1 t_stamp FROM tblBrewWhirlpool ORDER BY t_stamp DESC","FactorySQL")),now(),"minute")>=2 && (toint({[~]Brewhouse/West/WhirlPool/WhirlStatus.Quality},-1)!=192 || {[~]Brewhouse/West/WhirlPool/WhirlStatus}>0),1,0)
```

For some reason this perticular one keeps giving me an error.

> [@](#):
>
> GatewayException: String or binary data would be truncated.  
> caused by BatchUpdateException: String or binary data would be truncated.

if i remove the toint() around the Quality the tag will save, but it will not evaluate correctly because the value is not an integer.

Thank you,

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [October 27, 2011, 12:20am UTC](https://forum.inductiveautomation.com/t/db-tag-expression-error/3502/2 "2011-10-27T00:20:13Z")

</div>

Where is your tag stored? In the internal database or in an external SQL database? My guess is that the column we store the expression in is only 255 characters long. That is why it would work when you remove the toInt function.

If it is the external database you can alter the strval column on the sqlt\_meta table to accept more than 255 characters.

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [October 27, 2011, 3:32pm UTC](https://forum.inductiveautomation.com/t/db-tag-expression-error/3502/3 "2011-10-27T15:32:50Z")

</div>

Thanks, I changed the column in the external MS SQL Server database to varchar(MAX) and now the expression will update.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 31, 2011, 9:50am UTC](https://forum.inductiveautomation.com/t/db-tag-expression-error/3502/4 "2011-10-31T09:50:36Z")

</div>

I know this was already fixed, but wouldn’t executeScalarQuery eliminate the need for the TOP 1 in the query? Kind of like saying the first one of the top one… ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [October 31, 2011, 3:02pm UTC](https://forum.inductiveautomation.com/t/db-tag-expression-error/3502/5 "2011-10-31T15:02:45Z")

</div>

No, executeScalarQuery requires that a single value comes back which means 1 row 1 column.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 31, 2011, 4:14pm UTC](https://forum.inductiveautomation.com/t/db-tag-expression-error/3502/6 "2011-10-31T16:14:17Z")

</div>

Okay, then what’s the advantage of using it over a “normal” query that gives you the same result?

Not trying to be odd-- or more than normal. I just can’t quite visualize this yet.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [October 31, 2011, 4:19pm UTC](https://forum.inductiveautomation.com/t/db-tag-expression-error/3502/7 "2011-10-31T16:19:08Z")

</div>

If your query is returning just a single value, by using executeScalarQuery you don’t have to use the square brackets to go inside to get the value out.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 31, 2011, 7:16pm UTC](https://forum.inductiveautomation.com/t/db-tag-expression-error/3502/8 "2011-10-31T19:16:33Z")

</div>

Ok! Thanks for the info, Travis!
