|
24.11.2012, 00:08 | #1 |
Участник
|
Query ranges OR condition
Hi,
The following code sample: Query q = new Query(); QueryBuildDataSource qbds; ; qbds = q.addDataSource(tablenum(Table1)); SysQuery::findOrCreateRange(qbds, fieldnum(Table1, Field1)).value(a); SysQuery::findOrCreateRange(qbds, fieldnum(Table1, Field2)).value(b); Both ranges for Field1 and Field2 works as AND expression. Is it possible somehow handle those ranges as OR expression, between those fields? |
|
24.11.2012, 12:21 | #2 |
MCT
|
AND and OR clauses
This example will help you.
You may use both clauses in one expression. X++: queryBuildRange.value(strFmt('((%1 == %2) || ((%1 == %3) && (%4 == "%5")))', fieldStr(InventTable, ItemType), any2int(ItemType::Service), any2int(ItemType::Item), fieldStr(InventTable, ProjCategoryId), queryValue("Spares")));
__________________
Axapta book for developer |
|
24.11.2012, 17:08 | #3 |
Участник
|
Thanks
|
|
24.11.2012, 18:14 | #4 |
Участник
|
Цитата:
Сообщение от MikeR
This example will help you.
You may use both clauses in one expression. X++: queryBuildRange.value(strFmt('((%1 == %2) || ((%1 == %3) && (%4 == "%5")))', fieldStr(InventTable, ItemType), any2int(ItemType::Service), any2int(ItemType::Item), fieldStr(InventTable, ProjCategoryId), queryValue("Spares"))); |
|
24.11.2012, 20:30 | #5 |
Участник
|
That's not quite correct, it works for other field types, too, but you have to format literals in a slightly different way. E.g. string literals must be enclosed in double quotes and dates must be formatted in X++ way (yyyy\mm\dd).
|
|
24.11.2012, 22:09 | #6 |
Участник
|
Цитата:
Query q = new Query(); QueryBuildDataSource qbds; QueryRun qr; QueryBuildRange qbr; CustTable custTable; ; qbds = q.addDataSource(tablenum(CustTable)); qbr = SysQuery::findOrCreateRange(qbds, fieldnum(CustTable, AccountNum)); qbr.value(strfmt('((%1 == %2) || (%3 == %4))', fieldStr(CustTable, AccountNum),"000015", fieldStr(CustTable, InvoiceAccount),"000023")); qr = new QueryRun(q); if (qr.prompt()) { while (qr.next()) { custTable = qr.get(tablenum(CustTable)); info(strfmt("AccountNum: %1; InvoiceAccount: %2", custTable.AccountNum, custTable.InvoiceAccount)); } } |
|
24.11.2012, 22:23 | #7 |
Участник
|
String literals must be enclosed in double quotes Try this:
X++: // ... qbr.value(strfmt('((%1 == "%2") || (%3 == "%4"))', // ... |
|
24.11.2012, 22:42 | #8 |
Участник
|
|
|
|
|