Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.73 KB | None | 0 0
  1. USE TestDB
  2. DROP PROCEDURE  IF EXISTS dbo.move_money;
  3. GO
  4. CREATE PROCEDURE dbo.move_money @bill_from_id int, @bill_to_id int, @sum float
  5. AS
  6. declare @money_from float,@money_to float;
  7.  
  8. select @money_from = bills.money from dbo.bills where bills.id = @bill_from_id;
  9. select @money_to = bills.money from dbo.bills where bills.id = @bill_to_id;
  10.  
  11. if @money_from  is not null and @money_to is not null
  12. begin
  13.     if @money_from > @sum
  14.     begin
  15.     update dbo.bills set bills.money = bills.money - @sum where id = @bill_from_id;
  16.     update dbo.bills set bills.money = bills.money + @sum where id = @bill_to_id;
  17.     select 'Success! ';
  18.     end
  19. end
  20. else
  21. select 'wrong @bill_from_id and @bill_to_id';
  22.  
  23. SELECT *, @money_from, @money_to FROM dbo.bills;
  24. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement