tsql - Running Totals with debit credit and previous row SQL Server 2012 -
i having problems in recalculating running totals. i have situation have duplicate transactions , these must deleted , and initial , closing balance must recalculated based on amount , taking account when isdebit. my attempt have nested cursors (parent-child) , parent select distinct bookingno , child calculation looks messy , didn't work, didn't post because didn't want confuse things. i know in sql server 2012 can use ( sum on partition by ) cannot figure how handle deleted row etc.. below did far --create table testing if object_id(n'testtransaction', 'u') not null drop table testtransaction go create table [testtransaction] ( [id] [bigint] identity(1,1) not null, [bookingno] [bigint] not null, [isdebit] [bit] not null, [amount] [decimal](18, 2) not null, [initialbalance] [decimal](18, 2) not null, [closingbalance] [decimal](18, 2) not null ) on [primary] go i...