# Using the result of a query?

**URL:** <https://forum.inductiveautomation.com/t/using-the-result-of-a-query/3457>\
**Category:** Ignition\
**Created:** [October 18, 2011, 9:10pm UTC](https://forum.inductiveautomation.com/t/using-the-result-of-a-query/3457 "2011-10-18T21:10:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott\_rister](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@scott\_rister](https://forum.inductiveautomation.com/u/scott_rister)\
**Post date:** [October 18, 2011, 9:10pm UTC](https://forum.inductiveautomation.com/t/using-the-result-of-a-query/3457/1 "2011-10-18T21:10:17Z")

</div>

How can i get the result of a query and use it another?  
I have a db table which represents a recipe. when the user adds a row to the table I would like to automatically increment the “step No”. when adding the new row.

I am using the following Query to get the number of steps:  
GetStep = “Select Count(StepNo) From %s” % (RecipeName)  
NextStep = system.db.runQuery(GetStep, ‘Recipes’)

The query itself works but NextStep does not contain the value, at least not in a useable form to perform the “insert Into” query like:  
Query = “Insert Into template (StepNo) Values (%s)” % (NextStep)  
#system.db.runUpdateQuery(Query, ‘Recipes’)

Thanks for any help.  
Scott

---

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [October 18, 2011, 11:04pm UTC](https://forum.inductiveautomation.com/t/using-the-result-of-a-query/3457/2 "2011-10-18T23:04:11Z")

</div>

Scott,  
I’m not sure which Database you are using, but the NextStep variable you are getting as a result from the system.db.runQuery() command is a dataset rather than a single value.

try system.db.runScalarQuery(). It returns a single value.

---

<div class="post-metadata">

**Author:** ![scott\_rister](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@scott\_rister](https://forum.inductiveautomation.com/u/scott_rister)\
**Post date:** [October 19, 2011, 12:21am UTC](https://forum.inductiveautomation.com/t/using-the-result-of-a-query/3457/3 "2011-10-19T00:21:43Z")

</div>

Thanks, I had a few other “stoppers” as well but that was the biggie.  
i had tried that earlier, but the other problems kept me from pursuing it.
