以间隔计算金额

时间:2014-09-04 13:56:34

标签: sql navision

我有来自Navision的以下代码

PrintLine := FALSE;
LineTotalVendAmountDue := 0;
FOR i := 1 TO 5 DO BEGIN
  DtldVendLedgEntry.SETCURRENTKEY("Vendor No.","Initial Entry Due Date");
  DtldVendLedgEntry.SETRANGE("Vendor No.","No.");
  DtldVendLedgEntry.SETRANGE("Initial Entry Due Date",PeriodStartDate[i],PeriodStartDate[i + 1] - 1);
  DtldVendLedgEntry.CALCSUMS("Amount (LCY)");
  VendBalanceDue[i] := DtldVendLedgEntry."Amount (LCY)";
  VendBalanceDueLCY[i] := DtldVendLedgEntry."Amount (LCY)";
  IF VendBalanceDue[i] <> 0 THEN
    PrintLine := TRUE;
  LineTotalVendAmountDue := LineTotalVendAmountDue + VendBalanceDueLCY[i];
  TotalVendAmtDueLCY := TotalVendAmtDueLCY + VendBalanceDueLCY[i];
END;

我必须将上面的代码翻译成SQL server,但我无法理解。我是Navision的新手。

1 个答案:

答案 0 :(得分:0)

如果没有上下文,即使可以转换为SQL也很难,但基本上是:

对于5个日期间隔(PeriodStartDate数组中指定的每个的开始日期)加起来:

SELECT SUM([Amount (LCY)]) 
FROM [Company$Detailed Vendor Ledg. Entry] 
WHERE [Vendor No.] = $1 -- particular Vendor No.
AND [Initial Entry Due Date] BETWEEN $2 and $3 -- period start/end, inclusive

LineTotalVendAmountDue设置为特定供应商的总共5个间隔。

TotalVendAmtDueLCY设置为报告总计(可能)。