# Query with Multiple range

**URL:** <https://www.dynamicsuser.net/t/query-with-multiple-range/63458>\
**Category:** Developer Forum\
**Created:** [May 23, 2017, 10:39am UTC](https://www.dynamicsuser.net/t/query-with-multiple-range/63458 "2017-05-23T10:39:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SarathKumar](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@SarathKumar](https://www.dynamicsuser.net/u/SarathKumar)\
**Post date:** [May 23, 2017, 10:39am UTC](https://www.dynamicsuser.net/t/query-with-multiple-range/63458/1 "2017-05-23T10:39:43Z")

</div>

Hi,  
I wanted to set range for a field in the dynamic query, where that field is summed using addselectionfield in the query, Can we assign a range for the field result which is added up using selectionField:: sum using query , if possible how to add a range for that field in Ax 2009.

Thanks in Advance,  
Gopinath M

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [May 23, 2017, 10:48am UTC](https://www.dynamicsuser.net/t/query-with-multiple-range/63458/2 "2017-05-23T10:48:08Z")

</div>

> [@](#):
>
> Can we assign a range for the field result which is added up using selectionField:: sum using query

Can you elaborate this? If possible show us the code.

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [May 23, 2017, 10:52am UTC](https://www.dynamicsuser.net/t/query-with-multiple-range/63458/3 "2017-05-23T10:52:20Z")

</div>

If you want to filter records based on the result of the aggregation function (SUM), it’s not a usual range. SQL uses [HAVING](https://docs.microsoft.com/en-us/sql/t-sql/queries/select-having-transact-sql) for this purpose, which unfortunately isn’t supported by AX 2009. You would have to use a workaround, such as putting the result to a temporary table and filter records fetched from this temporary table.

Note that my understanding of your problem doesn’t match the title of your question, as it doesn’t involve any “Query with Multiple range”. Either I got it wrong, or you’re using a wrong title.

---

<div class="post-metadata">

**Author:** ![SarathKumar](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@SarathKumar](https://www.dynamicsuser.net/u/SarathKumar)\
**Post date:** [May 23, 2017, 11:29am UTC](https://www.dynamicsuser.net/t/query-with-multiple-range/63458/4 "2017-05-23T11:29:58Z")

</div>

I have a query like,  
query = new Query();  
datasource = query.addDataSource(tableNum(CustInvoiceJour));  
datasource.addGroupByField(fieldNum(CustInvoiceJour,OrderAccount));  
query.dataSourceTable(tableNum(CustInvoiceJour)).orderMode(OrderMode::GroupBy); query.dataSourceTable(tablenum(CustInvoiceJour)).addSelectionField(fieldnum(CustInvoiceJour,InvoiceAmount),SelectionField::Sum);  
for this amount field if the resultant added value is greater than a value say 20000 I should print that in info , this should be achieved using query in ax 2009

---

<div class="post-metadata">

**Author:** ![kranthi](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@kranthi](https://www.dynamicsuser.net/u/kranthi)\
**Post date:** [May 23, 2017, 11:47am UTC](https://www.dynamicsuser.net/t/query-with-multiple-range/63458/5 "2017-05-23T11:47:36Z")

</div>

If so, i think Marin has already answered you.
