Adding 2 ranges of the same field to a query and set the condition to AND

Hello,

I am trying to do a query using the query class, but when adding to ranges of the same field, the condition its an OR and I need it to be an AND, for example in the following code I get the records where the values of Field1 ara from 1 to 6 and I would like to get only the records where the values of Field1 are from 4 to 5, like an AND in the ranges conditions.

This is because just some data of the table should be included in the result and from that data the user can select an specific range.

q = new Query();

qbd = q.addDataSource(TableNum(TablaA));

qbr = qbd.addRange(FieldNum(TablaA, field1));

qbr.value(“1…5”);

qbr = qbd.addRange(FieldNum(TablaA, field1));

qbr.value(“4…6”);

qr = new QueryRun(q);

while (qr.next()) {

tablaA = qr.Get(tableNum(TablaA));

//Something…

}

Result Query:

SELECT * FROM TablaA WHERE ((Field1>=N’1’ AND Field1<=N’5’) OR (Field1>=N’4’ AND Field1<=N’6’))

Query needed (AND instead of OR):

SELECT * FROM TablaA WHERE ((Field1>=N’1’ AND Field1<=N’5’) AND (Field1>=N’4’ AND Field1<=N’6’))

I first tried to run a query with the first range and save the result to a table and then do an other query with the second range, but since it retrieves thousands of records it takes hours…

Thanks in Advance!