AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX: За рубежом > DAX in English
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 24.11.2012, 00:08   #1  
Kent is offline
Kent
Участник
 
46 / 10 (1) +
Регистрация: 24.01.2007
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  
MikeR is offline
MikeR
MCT
Аватар для MikeR
MCBMSS
Лучший по профессии 2015
Лучший по профессии 2014
 
1,628 / 627 (24) +++++++
Регистрация: 28.11.2005
Адрес: просто землянин
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  
Kent is offline
Kent
Участник
 
46 / 10 (1) +
Регистрация: 24.01.2007
Thanks
Старый 24.11.2012, 18:14   #4  
Kent is offline
Kent
Участник
 
46 / 10 (1) +
Регистрация: 24.01.2007
Цитата:
Сообщение от 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")));
But it seems, it works only for enum type fields...
Старый 24.11.2012, 20:30   #5  
gl00mie is offline
gl00mie
Участник
MCBMSS
Most Valuable Professional
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,684 / 5788 (200) ++++++++++
Регистрация: 28.11.2005
Адрес: Москва
Записей в блоге: 3
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  
Kent is offline
Kent
Участник
 
46 / 10 (1) +
Регистрация: 24.01.2007
Цитата:
Сообщение от gl00mie Посмотреть сообщение
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).
Hi, I tried, but without result:

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  
gl00mie is offline
gl00mie
Участник
MCBMSS
Most Valuable Professional
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,684 / 5788 (200) ++++++++++
Регистрация: 28.11.2005
Адрес: Москва
Записей в блоге: 3
String literals must be enclosed in double quotes Try this:
X++:
// ...
qbr.value(strfmt('((%1 == "%2") || (%3 == "%4"))',
// ...
Старый 24.11.2012, 22:42   #8  
Kent is offline
Kent
Участник
 
46 / 10 (1) +
Регистрация: 24.01.2007
Цитата:
Сообщение от gl00mie Посмотреть сообщение
String literals must be enclosed in double quotes Try this:
X++:
// ...
qbr.value(strfmt('((%1 == "%2") || (%3 == "%4"))',
// ...
Yes, this is correct way. Whole hour looked at query and didn't sigth that nuance.

Thank You!
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
ax-erp: X++ Code to get the Ranges / Criteria from Query Blog bot DAX Blogs 0 12.06.2012 12:11
daxline: How to add empty ranges in query Blog bot DAX Blogs 0 28.06.2011 19:11
daxline: SysQuery::findOrCreateRange() - A better way to create dynamic query ranges Blog bot DAX Blogs 0 28.01.2011 23:14
jinx: Dynamics AX – Query-Ranges und Filtereinstellungen des Benutzers Blog bot DAX auf Deutsch 0 04.02.2010 00:05
paruvella: Dynamics Ax - Simple SSRS report example by using Ax-Query and Ranges Blog bot DAX Blogs 0 08.01.2010 16:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 01:24.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.