如何从一个表中扣除值并插入另一个表中
问题描述:
我正在开发银行域名我想从表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