mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-10-07 07:36:54 +01:00
Correct severe misconception about SetCurrentKey in the knowledge base
This commit is contained in:
parent
841b4e7cab
commit
6e321d3c56
6 changed files with 74 additions and 40 deletions
|
|
@ -0,0 +1,20 @@
|
|||
codeunit 50231 "Perf Sample SetCurrentKey Bad"
|
||||
{
|
||||
// Misconception: SetCurrentKey does NOT tell SQL Server to use this index.
|
||||
// The optimizer picks the index from the filters (WHERE clause) and statistics.
|
||||
// The result order is never used here, so SetCurrentKey only adds an ORDER BY
|
||||
// the query does not need — and can push the plan toward a sort.
|
||||
procedure SumRemainingAmount(CustomerNo: Code[20]) Total: Decimal
|
||||
var
|
||||
CustLedgerEntry: Record "Cust. Ledger Entry";
|
||||
begin
|
||||
CustLedgerEntry.SetCurrentKey("Customer No.", Open, "Posting Date");
|
||||
CustLedgerEntry.SetRange("Customer No.", CustomerNo);
|
||||
CustLedgerEntry.SetRange(Open, true);
|
||||
CustLedgerEntry.SetAutoCalcFields("Remaining Amount");
|
||||
if CustLedgerEntry.FindSet() then
|
||||
repeat
|
||||
Total += CustLedgerEntry."Remaining Amount";
|
||||
until CustLedgerEntry.Next() = 0;
|
||||
end;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue