# Expression Tags including SQL Query

**URL:** <https://forum.inductiveautomation.com/t/expression-tags-including-sql-query/5692>\
**Category:** Ignition\
**Created:** [January 17, 2013, 2:12pm UTC](https://forum.inductiveautomation.com/t/expression-tags-including-sql-query/5692 "2013-01-17T14:12:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://forum.inductiveautomation.com/u/Ivan)\
**Post date:** [January 17, 2013, 2:12pm UTC](https://forum.inductiveautomation.com/t/expression-tags-including-sql-query/5692/1 "2013-01-17T14:12:46Z")

</div>

I’m trying to get values from a table and make a calculation with them. Is it possible to include all this in an expression tag?

I found out the Expression Function executeQuery and used this script as a test :

executeQuery(“SELECT tool1 FROM table WHERE ndx=500”,“Result”)  
getDatasetValueByIndex(“Result”,0,0,-1)

I should get a single int value, but nothing seems to work.

Of course this is a dumb test as I could use a Query Tag to do this, but what I actually want to achieve is to get multiple values before I make my calculation.

By the way the User Manual is not up to date considering Expression Tags since it still talks about DB Tags.

---

<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:** [January 17, 2013, 4:37pm UTC](https://forum.inductiveautomation.com/t/expression-tags-including-sql-query/5692/2 "2013-01-17T16:37:07Z")

</div>

I think you are trying to do this with a single expression tag, right? You want to query multiple values and do a calculation off of them. If so, you can query multiple values using the executeScalarQuery expression function on an expression tag. Something like this:`toInt(executeScalarQuery("SELECT tool1 FROM table WHERE ndx = 500", "DatabaseName")) + toInt(executeScalarQuery("SELECT tool1 FROM table WHERE ndx = 501", "DatabaseName"))`
