使用临时表更新数据 [英] Update data using temp table

查看:538
本文介绍了使用临时表更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2张桌子。从第一张桌子我得到的总和必须支付。

我得到的总数为60000.

另一张表格的数据如下所示

ID paidPrice剩余价格

1 10000 50000

2 5000 45000

3 15000 30000



现在如果总计得到70000,那么我想要更正第二个表的每个剩余价格如下

ID paidprice RemainingPrice

1 10000 60000

2 5000 55000

3 15000 40000



Plz帮助我。



我尝试了什么:



我使用临时表和光标但是我不要通过id获取记录来准确更新每一行。如果有另一种方法来更新它,那么plz建议我

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

推荐答案

假设总表中只有一行:

Assuming there is only one row in the total table:
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.


这篇关于使用临时表更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆