# Named query error "out of index"

**URL:** <https://forum.inductiveautomation.com/t/named-query-error-out-of-index/60615>\
**Category:** Ignition\
**Tags:** namedqueries, ignition80, perspective, database\
**Created:** [June 10, 2022, 2:16pm UTC](https://forum.inductiveautomation.com/t/named-query-error-out-of-index/60615 "2022-06-10T14:16:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![IA\_old\_forum](https://avatars.discourse-cdn.com/v4/letter/i/7ab992/32.png) [@IA\_old\_forum](https://forum.inductiveautomation.com/u/IA_old_forum)\
**Post date:** [June 10, 2022, 2:16pm UTC](https://forum.inductiveautomation.com/t/named-query-error-out-of-index/60615/1 "2022-06-10T14:16:55Z")

</div>

I am trying to return the max value for a row between 2 predefined time stamps from my DB but I keep getting error out of index.

the named query:

```auto
/*SELECT TOP 1 "nCycles_Trex_01","nGoodParts_Trex_01","nCycles_Trex_02","nGoodParts_Trex_02" FROM TrexTest00 WHERE t_stamp <= :date ORDER BY trextest00_ndx DESC 
*/

--SELECT MAX 'nCycles_Trex_01',"nGoodParts_Trex_01","nCycles_Trex_02","nGoodParts_Trex_02" FROM TrexTest00 WHERE t_stamp >= :date AND t_stamp <= :date_end
 --SELECT :date --AND ADDTIME( ':date' , 20 )
SELECT MAX(nCycles_Trex_01) FROM TrexTest00 WHERE t_stamp >= '2022-6-09 13:59:16' AND t_stamp <= '2022-6-09 13:59:20' --where CONVERT(Time, t_stamp) BETWEEN CONVERT(Time, :date ) and CONVERT(Time, :date_end ) 

```

I have tried all those different approaches (every line) but keep getting the error when I try to use the max function. I have 2 dateTime parameters for the corresponding start and end date

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/0/909e64cb5aa4da1415d3469b39d2e2f8d1507a02.png)

Does anyone know why it isnt working?

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [June 10, 2022, 2:25pm UTC](https://forum.inductiveautomation.com/t/named-query-error-out-of-index/60615/2 "2022-06-10T14:25:41Z")

</div>

To pass parameters this way, this must be a named query, right? When you test the named query in the ‘Testing’ tab, does it return any results?

---

<div class="post-metadata">

**Author:** ![IA\_old\_forum](https://avatars.discourse-cdn.com/v4/letter/i/7ab992/32.png) [@IA\_old\_forum](https://forum.inductiveautomation.com/u/IA_old_forum)\
**Post date:** [June 10, 2022, 2:28pm UTC](https://forum.inductiveautomation.com/t/named-query-error-out-of-index/60615/3 "2022-06-10T14:28:58Z")

</div>

When I test the named query that error message above appears (The index is out of range). When I bind a component to it I also get the same error

---

<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:** [June 10, 2022, 2:29pm UTC](https://forum.inductiveautomation.com/t/named-query-error-out-of-index/60615/4 "2022-06-10T14:29:36Z")

</div>

Have you tried it as you posted it here or were you just condensing all of your tries into a single code block?

Named Queries do not handle comments well all of the time, especially if the comments include parameters.

> [@Comments in named queries?](https://forum.inductiveautomation.com/t/comments-in-named-queries/53709/2):
>
> Comments are fine, it’s just that our parser is (currently) too dumb to distinguish a commented parameter from a legitimate one, so: SELECT \* FROM TABLE WHERE A = :param --AND B = :param2 Should be fine, but is what currently throws an error, because the parser thinks it needs an additional value for param2.

Also, can you show the details of the error, preferably in a code block.

---

<div class="post-metadata">

**Author:** ![IA\_old\_forum](https://avatars.discourse-cdn.com/v4/letter/i/7ab992/32.png) [@IA\_old\_forum](https://forum.inductiveautomation.com/u/IA_old_forum)\
**Post date:** [June 10, 2022, 2:34pm UTC](https://forum.inductiveautomation.com/t/named-query-error-out-of-index/60615/5 "2022-06-10T14:34:14Z")

</div>

Deleting the commented lines was the solution. Thanks!
