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
 complex query with cursor

Author  Topic 

rajnidas
Yak Posting Veteran

97 Posts

Posted - 2014-09-12 : 01:37:30
hi all,

SELECT debit.ACCOUNT_NO, debit.Serviced_Amt,credit.Tran_Amt,credit.Serviced_Flag
FROM tbl_Interest_Debit as debit
inner join
tbl_Credit as credit
on debit.ACCOUNT_NO=credit.Account_No
order by credit.TRANSACTION_VALUE_DATE

getting result
-------------------

ACCOUNT_NO Serviced_Amt Tran_Amt Serviced_Flag
------------ --------------- ------------ ------------
45505000661 1013088.00 19157467.00 0
45505000661 1013088.00 18988.96 0
33105126375 286533.00 171084.00 0
33105126375 286533.00 500000.00 0
33105126375 286533.00 1000000.00 0
33105126375 286533.00 800000.00 0
33105126375 286533.00 1000000.00 0
33105126375 286533.00 1000000.00 0

I want that service_amount should be subtracted from tran_amt until service_amount become zero
Once service_amount becomes zero service_flag should be changed to 1. using with cursor kindly need help

thanks

Rajnidas

Arun Babu N
Starting Member

26 Posts

Posted - 2014-09-12 : 03:13:38
post the expected result output

Arun Babu N
Go to Top of Page

rajnidas
Yak Posting Veteran

97 Posts

Posted - 2014-09-12 : 05:00:59


i need result is given below


ACCOUNT_NO Serviced_Amt Tran_Amt Serviced_Flag
------------ --------------- ------------ ------------
45505000661 0 19157467.00 1
45505000661 0 18988.96 1
33105126375 0 171084.00 1
33105126375 0 500000.00 1
33105126375 0 1000000.00 1
33105126375 0 800000.00 1



thanks

rajnidas
Go to Top of Page
   

- Advertisement -