# Using a parameter in a CASE statement in a named query (JDBC)

**URL:** <https://forum.inductiveautomation.com/t/using-a-parameter-in-a-case-statement-in-a-named-query-jdbc/35629>\
**Category:** Ignition Early Access\
**Created:** [June 14, 2020, 11:27am UTC](https://forum.inductiveautomation.com/t/using-a-parameter-in-a-case-statement-in-a-named-query-jdbc/35629 "2020-06-14T11:27:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirsten.chambers](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kirsten.chambers](https://forum.inductiveautomation.com/u/kirsten.chambers)\
**Post date:** [June 14, 2020, 11:27am UTC](https://forum.inductiveautomation.com/t/using-a-parameter-in-a-case-statement-in-a-named-query-jdbc/35629/1 "2020-06-14T11:27:36Z")

</div>

Hi all,

(Ignition 8.0.13, SQL Server 2017, default Microsoft SQLServer JDBC Driver)

In my quest for mobile performance, I’m attempting to limit query results on a table when a user is on a mobile device while not impacting desktop users. To that end, I’ve tried to make a named query like the following (where `:isMobile` is a boolean param):

```auto
SELECT TOP (CASE :isMobile WHEN 1 THEN 250 ELSE 9223372036854775807 END) -- no performance penalty for huge TOP() 
    <my_columns>
FROM <my_table>

```

However, this produces an error:

`com.microsoft.sqlserver.jdbc.SQLServerException: The number of rows provided for a TOP or FETCH clauses row count parameter must be an integer.`

Casting `:isMobile` to bool/int/what have you doesn’t help, nor does storing it in a variable.

This query works in the Database Query Browser when I replace `isMobile` with a constant, which leads me to believe the named query parameter replacement is what’s not playing nice with the JDBC.

Is there a way around this, or am I just barking up the wrong tree with this solution? Any insight appreciated.

Thanks!

---

<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:** [June 14, 2020, 11:32am UTC](https://forum.inductiveautomation.com/t/using-a-parameter-in-a-case-statement-in-a-named-query-jdbc/35629/2 "2020-06-14T11:32:52Z")

</div>

You’ll have to use a querystring parameter that actually contains the 1 or 250 you desire: a TOP clause is structure, and the number with it apparently is too. At least in SQL Server. Your problem is not that the parameter is in a CASE statement, but that you are trying to use it in a TOP clause.

---

<div class="post-metadata">

**Author:** ![kirsten.chambers](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kirsten.chambers](https://forum.inductiveautomation.com/u/kirsten.chambers)\
**Post date:** [June 14, 2020, 11:51am UTC](https://forum.inductiveautomation.com/t/using-a-parameter-in-a-case-statement-in-a-named-query-jdbc/35629/3 "2020-06-14T11:51:46Z")

</div>

Thanks Phil! Changing `isMobile` to a QueryString did in fact do it. For future readers’ sakes, here’s what it looks like now (keeping in mind I’ll have to pass in ‘1’ into isMobile now when true):

```auto
SELECT TOP (CASE WHEN {isMobile}=1 THEN 250 ELSE 9223372036854775807 END) --
    <my_columns>
FROM <my_table>

```

(aside: thanks for constantly being a great presence on the forums. I greatly respect your dedication and willingness to spread knowledge and help others! 🙂 )
