example,
A table inv [Inventory]
----
VouNo int
VouDt datetime
InvId int
Qty Numeric(12,2) [+ if inward... - if Outward]
so,
Query is like below
select VouDt, InvId,
(select sum(Qty) from inv where VouDt< i.VouDt) as OpnQty,
sum(Qty) as Qty,
(select sum(Qty) from inv where VouDt< i.VouDt)- sum(Qty) as ClsQty
from Inv as i
where voudt >= '2012-04-01' and vouDt<='2012-04-30'
group by InvId,VouDt
Happy Coding!
:)