# Query tags sometimes fails during startup

**URL:** <https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476>\
**Category:** Ignition\
**Created:** [January 28, 2022, 11:53am UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476 "2022-01-28T11:53:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [January 28, 2022, 11:53am UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/1 "2022-01-28T11:53:39Z")

</div>

Hi  
I am scratching my head over problem with several query tags which are bound to the bottom banner label of the starting screen. Occasionally they keep failing which makes whole banner red and tags have an error - java.lang.nullpointexception

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/5/25616cc5817a06bb715732057cd37f36d6010d93.png)

Original code behind query tag (in properties selected as event driven ) looks like (actual names changed):

SELECT Level FROM Level\_Table

i made some changes to protect from the following:  
1 Null value if record is return but it is null by using Coalesce - if null then 0 value is default  
2 SELECT EXISTS to protect from query failing and no rows returned - if no records than 0 value is default

When i put the code below behind the tag and try to restart it it stays red all the time  
which make me feel i overcomplicated this 🙂 Any thoughts how to solve this?

if(SELECT EXISTS(SELECT Level FROM Level\_Table),SELECT COALESCE (Level,0) FROM Level\_Table,0)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 28, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/2 "2022-01-28T12:55:07Z")

</div>

Coalesce doesn’t work if there is no row result at all. For such cases you need to use a fallback outside the query.

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [January 28, 2022, 2:04pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/3 "2022-01-28T14:04:59Z")

</div>

Can you help me please bit more to understand what would fallback outside query mean in my case? My query tag is being fed to the label. Sometimes during startup after licence expiry this tag becomes red with the message described above.

In my modified query i use coalesce only if select exists is successful so there must be at least valid dataset  
Any thoughts?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 28, 2022, 2:32pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/4 "2022-01-28T14:32:32Z")

</div>

Show a screenshot of your binding for the banner label text.

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [January 28, 2022, 2:43pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/5 "2022-01-28T14:43:06Z")

</div>

thanks for your help again screenshot below. Just to make sure its clear - sometimes during startup both query tags and banner gets red so if I improve error handling there will still be issue with red query tags i guess?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/9/296bec58ceb06ab1842f9709a9230066f32efe1e.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 28, 2022, 2:55pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/6 "2022-01-28T14:55:50Z")

</div>

So that binding will simply propagate any bad quality from `../CurrentTotalCapacity`. Please show the SQL (screenshot) for the query tag definition.

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [January 28, 2022, 3:54pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/7 "2022-01-28T15:54:31Z")

</div>

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

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/b/2bda48628e2b6e6dfe2cb46111661870c0c7f61b.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 28, 2022, 4:34pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/8 "2022-01-28T16:34:26Z")

</div>

Are you sure that your `asrs_vwStorageCapacity` view will **always** return a row? If it doesn’t, coalesce won’t be applicable. Try this:

```auto
SELECT coalesce((SELECT L1_Level_Capacity FROM asrs_vwStorageCapacity), 0)

```

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [January 30, 2022, 4:24pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/9 "2022-01-30T16:24:56Z")

</div>

Hi Phil  
Yes you are correct -i am not sure if a row is always returned. I have just applied your solution for testing. I thought that to check if there are no rows i should use if(SELECT EXISTS(…),0) instead of coalesce but i did not get the syntax right for the last statement.  
Thanks for help

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [February 7, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/10 "2022-02-07T12:55:40Z")

</div>

i had this failure again and noticed that some query tags did not have datasource configured and failed. As silly as that ☹  
Not sure why default database connection sometimes was used and sometimes not but i need to remember not to leave datasource as blank

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 7, 2022, 1:24pm UTC](https://forum.inductiveautomation.com/t/query-tags-sometimes-fails-during-startup/55476/11 "2022-02-07T13:24:24Z")

</div>

Tags don’t belong to a project, so there’s no default to pick. Query tags always needs the datasource setting.
