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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 28.10.2006, 16:40   #1  
Blog bot is offline
Blog bot
Участник
 
25,631 / 848 (80) +++++++
Регистрация: 28.10.2006
Dynamics AX Geek: Using query()
Источник: http://AxGeek.spaces.live.com/Blog/c...DB13!148.entry
==============
As the name implies QueryRun is the executor of a query linked to it. To construct a query you want QueryRun to execute, you need build classes:
  • Query
  •  QueryBuildDataSource
  • QueryBuildRange
  • QueryBuildFieldList
  • QueryBuildLink
  • QueryBuildDynaLink
 
Today’s example will use the first four to demonstrate a query that sums the credit limit field in CustTable grouped by Country and Currency. Additionally a count field indicates how many records are represented in the sum. Ranges are implemented for AccountNum and Country, but the user is allowed to add additional range criteria in the dialog. To demonstrate the status() property I have locked it, so the user can not change it.
 
QueryRun
QueryRun executes the query. If needed the familiar query dialog can be opened before the query is run. This is done using the prompt() method. SysQueryRun extends QueryRun and has a total of 7 prompt*() methods, with different default behavior. For example promptAllowAddRange() would allow the user to add new where-conditions.
 
Query
A query represents the select statement. This is where all the strings come together.
 
QueryBuildDataSource
Using QueryBuildDataSources you add all the tables you want joined (just one in this example). This is also where you define how the resultset is to be sorted. The orderMode() method lets you define
  • OrderBy
  • GroupBy
 
QueryBuildRange
Ranges represent where conditions. Multiple ranges are connected with AND conditions. Unfortunately there is no easy way to change that.
 
QueryBuildFieldList
Represents the selected fields of the query. By default all fields are selected. In regular queries you probably wouldn’t use them that often, but when grouping this is the way to define which fields are calculated. SelectionField is an enum with the following values
  •  Avg
  • Count
  • Database
  • Max
  • Min
  • Sum   
 
The result of Test_Query on my test system looks something like this:
CA CAD     1120,00 (3 records)
CA USD      500,00 (1 records)
DE EUR        0,00 (1 records)
DK CAD     5000,00 (1 records)
DK EUR      300,00 (6 records)
DK GBP      560,00 (2 records)
ES EUR        0,00 (1 records)
IE EUR        0,00 (1 records)
NL EUR       20,00 (2 records)
NO EUR     3000,00 (1 records)
 
 
static void Test_Query(Args _args)
{
    CustTable            custTable;
    Query                query      = new Query();
    QueryRun             qr         = new queryRun(query);
    QueryBuildDataSource qbds       = qr.query().addDataSource(tableNum(CustTable));
    QueryBuildRange      qbrAccN    = qbds.addRange(fieldNum(CustTable,AccountNum));
    QueryBuildRange      qbrCountry = qbds.addRange(fieldNum(CustTable,Country));
    QueryBuildFieldList  qbfl       = qbds.fields();
    ;
 
    qbrAccN.value('4000..4050');
    qbrAccN.status(RangeStatus::Locked);
    qbrCountry.value('CA..NO');
 
    qbfl.addField(fieldNum(CustTable,CreditMax),SelectionField::Sum);
    qbfl.addField(fieldnum(CustTable,RecId),SelectionField::Count);
 
    qbds.addSortField(fieldnum(CustTable,Country));
    qbds.addSortField(fieldNum(CustTable,Currency));
    qbds.orderMode(OrderMode::GroupBy);
 
    if (qr.prompt())
    {
 
 
        while (qr.next())
        {
            custTable = qr.get(tableNum(CustTable));
 
            print strfmt("%1 %2 %3 (%4 records)",custTable.Country,custTable.Currency,
                         num2str(custTable.CreditMax,10,2,0,0),custTable.RecId);
        }
 
    }
 
    pause;
}




==============
Источник: http://AxGeek.spaces.live.com/Blog/c...DB13!148.entry
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Dynamics AX: Managing Your Supply Chain Using Microsoft Dynamics AX 2009 - Book Review Blog bot DAX Blogs 0 31.03.2009 23:06
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
Inside Dynamics AX 4.0: Usage Scenarios Blog bot DAX Blogs 0 04.10.2007 05:15
Сергей Герасимов: Что нового в Microsoft Dynamics AX 4.0 Blog bot DAX Blogs 0 16.01.2007 11:00
Dynamics AX: Why Dynamics AX beats SAP Blog bot DAX Blogs 0 10.01.2007 23:15

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 13:59.