# Problem to Execute SQL query on Roster type Calculated

**URL:** <https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738>\
**Category:** Ignition\
**Created:** [December 5, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738 "2023-12-05T19:37:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 5, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738/1 "2023-12-05T19:37:19Z")

</div>

Hello, I'am executing a SQl query when alarm is actived but it is not working.  
This the syntax that I'am using.  
`system.db.runNamedQuery("SELECT username FROM wind_users WHERE status = 2","DB")`  
I noticed this when I put a loger after this line of code.

In fact, the lines of code that follow do not execute.

I test on console : `system.db.runNamedQuery("SELECT username FROM wind_users WHERE status = 2")` it is workin.

but on calculated roster not working.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [December 5, 2023, 7:46pm UTC](https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738/2 "2023-12-05T19:46:16Z")

</div>

You are passing what looks like an actual SQL statement instead of the name of one of your saved named queries.

I think you should be using `runPrepQuery` not `runNamedQuery`. `runNamedQuery` is for running predefined named queries that are saved in your project.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 5, 2023, 7:49pm UTC](https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738/3 "2023-12-05T19:49:44Z")

</div>

thank you @ryan.white I just tryied all two function. but nothing is happen

---

<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:** [December 5, 2023, 7:51pm UTC](https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738/4 "2023-12-05T19:51:42Z")

</div>

Look at the documentation for these functions for the syntax requirements for the scope you need. Gateway scope (pipeline execution) is not the same thing as Designer scope.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [December 5, 2023, 7:56pm UTC](https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738/6 "2023-12-05T19:56:19Z")

</div>

Specifically, for Gateway scope, it seems that database the name is required, but you're not providing it.

Edit: Additionally, you will need to provide a list of arguments as well (even if it's an empty list in this case).

[https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepQuery](https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepQuery)

I wonder if there's any error message logged to the Gateway about this.

Anyway, the following:

```auto
system.db.runPrepQuery("SELECT username FROM wind_users WHERE status = 2", [], dbName)

```

should be the correct syntax.

EDIT 2: corrected typo in post, should be `runPrepQuery` not `runPredQuery`.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 5, 2023, 8:23pm UTC](https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738/7 "2023-12-05T20:23:46Z")

</div>

> [@Felipe\_CRM](#):
>
> Je me demande s'il y a un message d'erreur enregistré sur la passerelle à ce sujet.

I get that on log:

```auto

Logger	Time	Message
NotificationBlock	05Dec2023 21:22:45	Unable to parse calculated roster.
org.python.core.PyException: AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'runPredQuery'

at org.python.core.Py.AttributeError(Py.java:178)

at org.python.core.PyObject.noAttributeError(PyObject.java:965)

at org.python.core.PyObject. __getattr__ (PyObject.java:959)

at org.python.pycode._pyx177.calculateRoster$1(:19)

at org.python.pycode._pyx177.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyBaseCode.call(PyBaseCode.java:306)

at org.python.core.PyFunction.function ___call__ (PyFunction.java:474)

at org.python.core.PyFunction. __call__ (PyFunction.java:469)

at org.python.core.PyFunction. __call__ (PyFunction.java:459)

at org.python.core.PyFunction. __call__ (PyFunction.java:454)

at com.inductiveautomation.ignition.alarming.pipelines.blocks.NotificationBlock.getEvaluatedRosterFromScript(NotificationBlock.java:233)

at com.inductiveautomation.ignition.alarming.pipelines.blocks.NotificationBlock.sendNotification(NotificationBlock.java:131)

at com.inductiveautomation.ignition.alarming.pipelines.blocks.NotificationBlock$EvaluationContext.onEvaluate(NotificationBlock.java:374)

at com.inductiveautomation.ignition.alarming.pipelines.blocks.AbstractEvaluationContext.evaluate(AbstractEvaluationContext.java:78)

at com.inductiveautomation.ignition.alarming.pipelines.SingleThreadAlarmPipeline$QueueEvaluator.run(SingleThreadAlarmPipeline.java:187)

at java.base/java.lang.Thread.run(Unknown Source)

```

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [December 5, 2023, 8:25pm UTC](https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738/8 "2023-12-05T20:25:00Z")

</div>

> [@Felipe\_CRM](#):
>
> `system.db.runPredQuery(`

Looks like a typo, should be `system.db.runPrepQuery(`

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [December 5, 2023, 8:36pm UTC](https://forum.inductiveautomation.com/t/problem-to-execute-sql-query-on-roster-type-calculated/82738/9 "2023-12-05T20:36:02Z")

</div>

Oops, I need to proofread these posts before I send them.
