# Use an expression on a parameter in a Named Query

**URL:** <https://forum.inductiveautomation.com/t/use-an-expression-on-a-parameter-in-a-named-query/25094>\
**Category:** Ignition\
**Created:** [May 17, 2019, 9:21am UTC](https://forum.inductiveautomation.com/t/use-an-expression-on-a-parameter-in-a-named-query/25094 "2019-05-17T09:21:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nagewaza1009](https://avatars.discourse-cdn.com/v4/letter/n/838e76/32.png) [@nagewaza1009](https://forum.inductiveautomation.com/u/nagewaza1009)\
**Post date:** [May 17, 2019, 9:21am UTC](https://forum.inductiveautomation.com/t/use-an-expression-on-a-parameter-in-a-named-query/25094/1 "2019-05-17T09:21:07Z")

</div>

Hello everyone,

I am currently programming a Numeric Text Field binded with a Named Query.

The query is the following :

`SELECT AVG(floatvalue) FROM dbo.sqlt_data_1_{Year}_{Month} WHERE tagid = 1`

In my window i have two Dropdown Lists, from which you can choose the Month and the Year. The QueryString parameters are found through the expression `{Root Container.Dropdown 1.selectedStringValue}` (for the Year, and changing the name of the dropdown for the Month). Until this point everything works perfectly.

Now, what i want to know is whether it is possible to choose a Month and to access the data of the previous month. For instance, let’s say i pick Month 4 in the dropdown list but in my named query i actually want to access the data for Month 4 but also for Month 3 (which is in sqlt.data\_1\_YYYY\_03).

I can’t figure how to do this… I thought about writing a script which would process that (and tackle exceptions like Month 12 of Year 4 being the month before Month 1 of Year 5) but maybe someone here has already done something similar ?

Thank you in advance,

---

<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:** [May 17, 2019, 12:05pm UTC](https://forum.inductiveautomation.com/t/use-an-expression-on-a-parameter-in-a-named-query/25094/2 "2019-05-17T12:05:40Z")

</div>

You would have to construct the other strings externally and pass them as additional parameters. The SQL would need to nest a UNION query to combine the two source tables before the outer query applies your aggregate function. Avoiding this sort of complexity is why the Tag History Bindings exist.
