如何在Sql Server 2008中计算破坏余额。 我正在使用以下查询在sql server 2012中完美地工作,但在sql server 2008中没有。
SELECT empid, tentryno, glcode, descript, linenarrat, ttype, amount, tapplid, ftype, mentryno, mthttype, entrydate, ref, refdate, remarks, narrat, postflag, mapplid, mtype, post, acctheadcode, accthead, subacctheadcode, subaccthead
, CASE
WHEN ttype = 'D'
THEN amount
ELSE 0.00
END AS Debit, CASE
WHEN ttype = 'C'
THEN amount
ELSE 0.00
END AS Credit, SUM(CASE
WHEN ttype = 'D'
THEN amount
ELSE amount * - 1
END) OVER (
PARTITION BY glcode ORDER BY tseqid
) AS balance, STATUS, receid, system.title, dbo.system.address, dbo.system.phone1, dbo.system.phone2, dbo.system.fax, dbo.system.signimage, dbo.system.logo
FROM CreditDebitDetails
CROSS JOIN system
WHERE STATUS != 0