SET @BeginDate ='20100101'/* FROM JDT1 T0 WHERE T0.RefDate >= */ --'[%0]'
SET @EndDate = '20100330'/* FROM JDT1 T1 WHERE T1.RefDate <= */ --'[%1]'
SET @Account = '100101'/* FROM JDT1 T2 WHERE T2.Account = */ --'[%2]'
declare @期初 numeric(18, 4)
SELECT @期初=SUM(Debit - Credit) FROM JDT1 AS T2 WHERE (Account = @Account) AND (RefDate < @BeginDate)
SELECT 编号=TransId, 日期=RefDate, 科目=Account, 摘要=LineMemo,借方=Debit, 贷方=Credit, 累计余额=@期初 +
(SELECT SUM(Debit - Credit) AS 本期累计
FROM JDT1 AS T1
WHERE (Account = @Account) AND (TransId <= T0.TransId) AND (Line_ID <= T0.Line_ID))
FROM JDT1 AS T0
WHERE (Account = @Account) AND (RefDate >= @BeginDate) AND (RefDate <=@EndDate)
ORDER BY TransId, Line_ID