Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USE TestDB
- DROP PROCEDURE IF EXISTS dbo.move_money;
- GO
- CREATE PROCEDURE dbo.move_money @bill_from_id int, @bill_to_id int, @sum float
- AS
- declare @money_from float,@money_to float;
- select @money_from = bills.money from dbo.bills where bills.id = @bill_from_id;
- select @money_to = bills.money from dbo.bills where bills.id = @bill_to_id;
- if @money_from is not null and @money_to is not null
- begin
- if @money_from > @sum
- begin
- update dbo.bills set bills.money = bills.money - @sum where id = @bill_from_id;
- update dbo.bills set bills.money = bills.money + @sum where id = @bill_to_id;
- select 'Success! ';
- end
- end
- else
- select 'wrong @bill_from_id and @bill_to_id';
- SELECT *, @money_from, @money_to FROM dbo.bills;
- GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement