且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从一个表中扣除值并插入另一个表中

更新时间:2022-12-10 19:43:59

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





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