# Named query not working on label. PLZ help

**URL:** <https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938>\
**Category:** Ignition\
**Tags:** ignition80, database, scripting, perspective\
**Created:** [December 9, 2021, 1:16pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938 "2021-12-09T13:16:10Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Resistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/resistor/32/30634_2.png) [@Resistor](https://forum.inductiveautomation.com/u/Resistor)\
**Post date:** [December 9, 2021, 1:16pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/1 "2021-12-09T13:16:10Z")

</div>

I have a transaction group that counts the instances where a boolean tag is true.  
I use a named query

```auto
SELECT count(count1_ndx)
FROM count1
WHERE t_stamp > 1639054080257

```

to return the number of instances from a particular time stamp

when I want to show it in binded in a label text it gives me an error of null

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/5/65d0a7bb620ec86eea9c48e0341ce40bbbff701f.png)  
Apparently is of none type… what can I do?

I remember using named queries like this one in a table and obtaining the result, now even if I use a table I get the same error of null

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 9, 2021, 1:22pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/2 "2021-12-09T13:22:25Z")

</div>

The query is returning Null, which I will admit is a little odd.

If you open the Named query and run the query from the Testing tab, do you get the results you expect?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 9, 2021, 1:27pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/3 "2021-12-09T13:27:43Z")

</div>

And in the case you get the same thing in the Testing tab, what do you get if you run this query directly on your database? Just so we know the expected result.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 9, 2021, 1:41pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/4 "2021-12-09T13:41:04Z")

</div>

> [@bkarabinchak.psi](#):
>
> You don’t happen to have the transform script enabled without anything inside of it do you? Python functions when they lack a return function will automatically return None. If you’re transform script is enabled but blank I imagine that could be causing it.

I thought of that too, but the Query is also returning Null, but is configured to return a dataset. I would expect to see `Dataset[0 rows x 1 cols]`

Speaking of, the binding should probably be configured for `Scalar`

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 9, 2021, 1:44pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/5 "2021-12-09T13:44:07Z")

</div>

Yea I just tested it, doing a `return None` or erasing it does lead to a null result, not a class.org.python.core.PyNone.

Agreed, it looks like it should be scalar, in which case I’m unsure what you would need a transform script for. But it does appear to be one configured no?

@Resistor can you show the code from inside your transform script?

---

<div class="post-metadata">

**Author:** ![Resistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/resistor/32/30634_2.png) [@Resistor](https://forum.inductiveautomation.com/u/Resistor)\
**Post date:** [December 9, 2021, 1:48pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/6 "2021-12-09T13:48:08Z")

</div>

When I test the named query I get the numeric result back.

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

I only used the script to see which type of data it was returning, without it returns null… regardless of the return format(auto, scalar, etc.)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/1/61b4ba46aa5f5423d1501679d85e358d9a70bfd5.png)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 9, 2021, 1:53pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/7 "2021-12-09T13:53:01Z")

</div>

So to summarize - we expect to see 18, when you just bind to the namedQuery directly you get a null, and when you add transform script this turns into a PyNone? Very odd indeed. I’m out of ideas then.

Note you can always call Ignition Support, they’re very helpful, can remote in and help you troubleshoot directly.

---

<div class="post-metadata">

**Author:** ![Resistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/resistor/32/30634_2.png) [@Resistor](https://forum.inductiveautomation.com/u/Resistor)\
**Post date:** [December 9, 2021, 1:58pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/8 "2021-12-09T13:58:32Z")

</div>

Basically… and when I added the transform I used the type() function to see what type of data it was exactly.

Thanks anyway. I didn’t want to call because I barely know how to use the software and thought they only help troubleshooting but you needed to know how everything works

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 9, 2021, 2:06pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/9 "2021-12-09T14:06:49Z")

</div>

Oh well if you’re returning `type()` in your transform then it I can see why you get the PyNone at least.

You will get the most out of this forum generally speaking if you can show your code as well - that’s the only way any of us can really help you troubleshoot.

However the larger issue of your named query returning 18 in your testing tab but null in your binding is odd. The last thing I would ask - can you show your Authoring tab? I want to confirm the query in your Authoring tab matches what is shown in the binding.

_Maybe_ what is causing this is that your named query was edited but not saved, so the testing shows one result, but the binding is still using the old version. Is the name named query you’re looking at in _italics_ in the in the designer? Like this  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/c/6c71a144943454652348c118f85622750f1dcc27.png)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [December 9, 2021, 2:07pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/10 "2021-12-09T14:07:50Z")

</div>

> [@Resistor](#):
>
> `WHERE t_stamp > 1639054080257`

im not sure this is the best way to filter a t\_stamp tho  
might be mixing up second and milisecond based tstamps..

---

<div class="post-metadata">

**Author:** ![Resistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/resistor/32/30634_2.png) [@Resistor](https://forum.inductiveautomation.com/u/Resistor)\
**Post date:** [December 9, 2021, 2:10pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/11 "2021-12-09T14:10:15Z")

</div>

Of course  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/a/8ad1a8e338e7185463af4cef429c12a5d7636732.png)

I just now changed the name to see if the space I had before could have caused the problem. But it’s the same as in the last image I showed

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 9, 2021, 2:11pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/12 "2021-12-09T14:11:25Z")

</div>

Ok so its been edited. Save your project and reload you view. See if this fixes your issue.

Edit: I was able to recreate your basic problem. I created a named query that was `SELECT 2` and bound that to a label text. Then I edited the query without saving it (which leaves it in italics) to `SELECT 3`  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/1/a1e11ace8291aacff837030995e205b3960b1875.png)

But my label still is running the result of the old named query until I save it -  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/0/000eebc1336dfe7bb6a0eb14f13267a927d74d7a.png)

After saving:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/1/71785011b24b06d8861300936426bd21dddad54f.png)

So save your project and then recheck your binding please.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 9, 2021, 5:16pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/13 "2021-12-09T17:16:02Z")

</div>

Split this topic on December 9, 2021, 5:16pm UTC

3 posts were split to a new topic: [Transaction group date format](https://forum.inductiveautomation.com/t/transaction-group-date-format/53953)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [December 9, 2021, 2:15pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/14 "2021-12-09T14:15:45Z")

</div>

could you remove the last 3 numbers and run the query again?

---

<div class="post-metadata">

**Author:** ![Resistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/resistor/32/30634_2.png) [@Resistor](https://forum.inductiveautomation.com/u/Resistor)\
**Post date:** [December 9, 2021, 2:16pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/15 "2021-12-09T14:16:51Z")

</div>

But it was edited after it was returning null.

But yes, I think I hadn’t saved it and now it is working. Such a little thing gave me such a headache 😅

Thanks

btw do you know how I could change the t\_stamp format in the transaction group?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 9, 2021, 2:18pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/16 "2021-12-09T14:18:53Z")

</div>

Right, after you make edits to your named query for it to propagate your bindings you do have to save so that your NamedQuery does NOT appear in italics in the designer object tree. Glad that fixed it.

You might want to make a post for your separate time stamp problem however as to keep issues self contained to single threads to help people in the future who might search for the same problem.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [December 9, 2021, 2:21pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-on-label-plz-help/53938/18 "2021-12-09T14:21:40Z")

</div>

and on the binding? ah nvm it got sovled xd
