SHARE
TWEET

Untitled

a guest Oct 16th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE PROC usp_TransferMoney(@SenderId INT, @ReceiverId INT, @Amount DECIMAL(15, 4))
  2. AS
  3. BEGIN TRANSACTION
  4.         DECLARE @senderAccount INT =
  5.         (
  6.             SELECT Id
  7.               FROM Accounts
  8.              WHERE Id = @SenderId
  9.         );
  10.  
  11.         DECLARE @receiverAccount INT =
  12.         (
  13.             SELECT Id
  14.               FROM Accounts
  15.              WHERE Id = @ReceiverId
  16.         );
  17.  
  18.         IF (@senderAccount IS NULL)
  19.         BEGIN
  20.             ROLLBACK;
  21.             RAISERROR('Invalid sender account.', 16, 1);
  22.             RETURN;
  23.         END
  24.  
  25.         IF (@receiverAccount IS NULL)
  26.         BEGIN
  27.             ROLLBACK;
  28.             RAISERROR('Invalid receiver account.', 16, 2);
  29.             RETURN;
  30.         END;
  31.  
  32.         IF (@Amount < 0)
  33.         BEGIN
  34.             ROLLBACK;
  35.             RAISERROR('Amount should be bigeer than zero.', 16, 3);
  36.             RETURN;
  37.         END;
  38.  
  39.         EXEC dbo.usp_WithdrawMoney @SenderId, @Amount;
  40.         EXEC dbo.usp_DepositMoney @ReceiverId, @Amount;
  41. COMMIT;
  42.  
  43. EXEC usp_TransferMoney 5, 1, 5000
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top