# Insert Results of Named Query to Text Field

**URL:** <https://forum.inductiveautomation.com/t/insert-results-of-named-query-to-text-field/103046>\
**Category:** Ignition\
**Tags:** ignition81, vision, database, ignition79, python\
**Created:** [February 28, 2025, 2:08pm UTC](https://forum.inductiveautomation.com/t/insert-results-of-named-query-to-text-field/103046 "2025-02-28T14:08:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rich\_Knoll](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rich_knoll/32/73001_2.png) [@Rich\_Knoll](https://forum.inductiveautomation.com/u/Rich_Knoll)\
**Post date:** [February 28, 2025, 2:08pm UTC](https://forum.inductiveautomation.com/t/insert-results-of-named-query-to-text-field/103046/1 "2025-02-28T14:08:44Z")

</div>

Hello all,

I think this one should be easy but I'm a bit stumped.

I need to use a button to fire a named query which will return only one result and insert that result into a text field. I do not want to bind the text property of the text field to the named query because I want to control when it runs, which is why I am adding the script to the button.

Here is the query:

```python
SELECT cartID
FROM CommTrackCarts
WHERE startBuild = (
	SELECT MAX(startBuild) FROM CommTrackCarts
	WHERE cartNumber = :cartNumberParam )

```

And here is the script inside of my button:

```python
params = {
	"cartNumberParam": event.source.parent.getComponent('Cart').text
}

system.db.runNamedQuery("INSERT Cart", params)

event.source.parent.getComponent('CartID').text = str(system.db.runNamedQuery("SELECT MAX", params))

```

Right now, this places the dataset into the text field and I need it to return a specific item from the dataset:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/e/fefd65868c12ba603a70c6b5f2cc2dc28435a5ce.png)

Any and all help is greatly appreciated!

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [February 28, 2025, 2:35pm UTC](https://forum.inductiveautomation.com/t/insert-results-of-named-query-to-text-field/103046/2 "2025-02-28T14:35:14Z")

</div>

In the named query, change the query type to `scalar`. This will prompt it to return a single value instead of a dataset.

---

<div class="post-metadata">

**Author:** ![Rich\_Knoll](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rich_knoll/32/73001_2.png) [@Rich\_Knoll](https://forum.inductiveautomation.com/u/Rich_Knoll)\
**Post date:** [February 28, 2025, 4:14pm UTC](https://forum.inductiveautomation.com/t/insert-results-of-named-query-to-text-field/103046/3 "2025-02-28T16:14:23Z")

</div>

Fantastic!

Did not know what a scalar query did, but that was exactly what I needed. Thanks so much for the feedback. Such an easy fix! 😄

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 28, 2025, 8:01pm UTC](https://forum.inductiveautomation.com/t/insert-results-of-named-query-to-text-field/103046/4 "2025-02-28T20:01:06Z")

</div>

**scalar**  
/ˈskeɪlə/

Mathematics•Physics  
_adjective_

1. (of a quantity) having only magnitude, not direction. [A regular SQL query would have two dimensions; rows and columns.]

_noun_

1. a scalar quantity.

> **[Oxford Languages and Google - English | Oxford Languages](https://languages.oup.com/google-dictionary-en/)**
>
> Google’s English dictionary is provided by Oxford Languages. Oxford Languages is the world’s leading dictionary publisher, with over 150 years of experience creating and delivering authoritative dictionaries globally in more than 50 languages.
