如何从一个表中扣除值并插入另一个表中 [英] How to deduct values from one table and insert into another table

查看:75
本文介绍了如何从一个表中扣除值并插入另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发银行域名我想从表1中扣除一些金额并将这些值插入表2中......伙计们,请你帮忙提前谢谢

I'm working on Bank domain I would like to deduct some amount from Table 1 and insert these values into table 2...guys can you please help Thanks in advance

推荐答案

你可以按如下方式制作程序。





You can make procedure as follows.


ALTER PROCEDURE [dbo].[DeductAmountFrom1]
@Amount Decimal -- assumed amount is type of decimal
AS
BEGIN
   --scenario 1--
   --tablename == table which needs to update
   --amountcol = column which needs to update
   --filter condition == updation criteria
   --tablename2 ==  insertion required table
   --[column1,columns2] other columns name
   --insertamountcol == insertion required column name
   --[other columns value] ==other columns values

   Update tablename
   set
   amountcol= amountcol-@Amount
   where [filter condition]

   Insert into tablename2
   ([column1,columns2], insertamountcol]
   VALUES ([other columns value], @Amount);

END


这篇关于如何从一个表中扣除值并插入另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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