Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 table. From first table I am getting total rs which has to be paid.
I get total rs as 60000.
another table which data are like as follow
ID paidPrice Remainingprice
1 10000 50000
2 5000 45000
3 15000 30000

Now if total gets 70000, than I want to correct each and every remaining price of 2nd table as below
ID paidprice RemainingPrice
1 10000 60000
2 5000 55000
3 15000 40000

Plz help me.

What I have tried:

I used temp table and also cursor but I dont get record by id to update each row exactly. If there is another way to update it then plz suggest me
Posted
Updated 22-Jun-17 21:23pm
v2

1 solution

Assuming there is only one row in the total table:
SQL
UPDATE anothertable
SET RemainingPrice = total.rs - anothertable.PaidPrice
FROM anothertable
CROSS JOIN total

I didn't actually run thisso I hope there may be errors but the general idea is you need to join the two tables. Please note this doesn't do any validation so "total - paidprice" can be negative.
 
Share this answer
 
Comments
heta.dave 23-Jun-17 4:12am    
Thanks.. your solution helped me..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900