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
 General SQL Server Forums
 New to SQL Server Programming
 how to do that?

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2007-04-17 : 16:46:17
I have a table A:

mechantid loan lenghOfMonth Date
1 30000 8.3 4/1/2006
2 40000 6.3 5/1/2006
3 6000 4.5 3/1/2006
------------

Loan is amount of loan (no interest)to merchant length of months is the legthofmonth the merchannt suppose to pay off (for example, merchant 1 have loan 30000, need to pay off in 8.3 month. The first 8 month need to pay 30000/8.3 each month, the ninth month need to pay the rest 30000-8*30000/8.3)
I want to get how much I suppose to get each month, for example: May 2006, i sould get 30000/8.3+40000/6.3+6000/4.5
how can i do it using sql?

Thanks

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-17 : 16:59:24
Do you need the sum of all the amounts for all merchants? or sum for each merchant?

To start with you can do something like:

SELECT SUM(Convert(Decimal(10,2),Loan)/LengthOfMonth)
FROM TableA

and add conditions appropriately. When you say May 2006, how does that relate to the Date column in the table?


************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jeff06
Posting Yak Master

166 Posts

Posted - 2007-04-17 : 17:09:30
Thank your response.
The time is relavnet
for example
merchant 1 pay off his debt from april 06 to Nov 06 at 30000/8.3 each month, ant Dec. 06 pay off the rest
merchant 2 pay off her dent from May 06 to Nov 06 at 40000/6.3 each month and pay the rest in Dec. 06
Merchant 3 pay off her debt from march 06 ot Jun 06 at 6000/4.5 each month and pay off the rest in July 06
The patter is just like waterfall in finance
I want to know how much i get each month in a ceratin period.
Thanks
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-17 : 17:18:55
So the date column is the date the loan was approved?

quote:
Originally posted by jeff06

Thank your response.
I want to know how much i get each month in a ceratin period.



Once again, you want the total owed by each merchant?
The query I provided can return that result.




************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -