Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Summation with Transaction

Author  Topic 

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2011-02-01 : 15:29:26
Table A - Unique Records for a Member with Loan Amt
Ex: LoanAmt=10000 MemeberId=1

Table B - Transaction table for Table A. which has 10 rows with Recieved Amt on Due Date
Ex: MemberId=1 DueDate Recieved Amt
Jan 1 1000
Jan 2 1000
Jan 3 1000
Jan 4 1000
Jan 5 1000
Jan 6 1000
Jan 7 1000
Jan 8 1000
Jan 9 1000
Jan 10 1000

SELECT MemeberName,LoanAmt,SUM(Recieved),(LoanAmt-(SUM(Recieved)) As PrincipleOutstanding
FROM Table A INNER JOIN Table B ON A.MemberId=B.MemberId
GROUP BY MemeberName,LoanAmt
Outstanding=LoanAmt-SUM(RecievedAmt)
Ex: Outstanding=10000-SUM(RecievedAmt)
10000-10000=0

But I Need the Outstanding Amt for Each Day:

SELECT MemeberName,LoanAmt,DueDate,Recieved,(LoanAmt-(Recieved)) As PrincipleOutstanding
FROM Table A INNER JOIN Table B ON A.MemberId=B.MemberId
GROUP BY MemeberName,LoanAmt,DueDate,Recieved

From Above Calculation am getting as
Jan 1 10000-1000=9000
Jan 2 10000-1000=9000
.....................
.....................
.....................
Jan 10 10000-1000=9000

The above Result is wrong. I need the Calculation Thru Query from the column. Output should be

Jan1 10000-1000=9000
Jan2 9000-1000=8000
Jan3 8000-1000=7000
...................
...................
....................
Jan10 1000-1000=0


Please help me in this to find the soln. Have to get from above columns not other than that...

Regards,
Kalaiselvan R
Love Yourself First....

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-11 : 10:10:16
Search for Running total in this forum

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-02-12 : 04:04:32
see scenario 1

http://visakhm.blogspot.com/2010/01/multipurpose-apply-operator.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -