Показать сообщение отдельно
Старый 13.02.2015, 13:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,644 / 848 (80) +++++++
Регистрация: 28.10.2006
palleagermark: Select Count Distinct
Источник: http://www.agermark.com/2015/02/sele...-distinct.html
==============

The Select statement doesn't have a way let you do a count of distinct records.

Today I found this neat way to do it anyway, in the method \Data Dictionary\Tables\LedgerJournalTable\Methods\numOfVouchers:
...
sql = 'select count(distinct %1) from %2 where %3 = %4 and %5 = %6 and %7 = %8';

sql = strFmt(sql,
ReleaseUpdateDB::backendFieldName(tableNum(LedgerJournalTrans), fieldNum(LedgerJournalTrans, Voucher)),
ReleaseUpdateDB::backendTableName(tableNum(LedgerJournalTrans)),
ReleaseUpdateDB::backendFieldName(tableNum(LedgerJournalTrans), fieldNum(LedgerJournalTrans, JournalNum)),
sqlSystem.sqlLiteral(this.JournalNum),
ReleaseUpdateDB::backendFieldName(tableNum(LedgerJournalTrans), fieldNum(LedgerJournalTrans, DataAreaId)),
sqlSystem.sqlLiteral(ledgerJournalTrans.DataAreaId),
ReleaseUpdateDB::backendFieldName(tableNum(LedgerJournalTrans), fieldNum(LedgerJournalTrans, Partition)),
getcurrentpartitionrecid());
...


Источник: http://www.agermark.com/2015/02/sele...-distinct.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.