home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / BENCHSQL.ZIP / TP1ONLY.SQL < prev    next >
Text File  |  1989-06-30  |  1KB  |  65 lines

  1. use bench
  2. go
  3.  
  4. create procedure tp1 @acct int, @teller int, @branch int, @delta int,
  5. @transid int=0, @pid int=0, @inbuff char(100) as
  6.  
  7. declare @balance int
  8. declare @outbuff char(200)
  9.  
  10. select @outbuff = "12345678901234567890123456789012345678901234567890" 
  11.                 + "12345678901234567890123456789012345678901234567890" 
  12.                 + "12345678901234567890123456789012345678901234567890" 
  13.                 + "12345678901234567890123456789012345678901234567890" 
  14.  
  15. begin tran
  16.  
  17. /*fetch current balance for account*/
  18. select @balance = balance
  19. from account
  20. where number=@acct
  21.  
  22. /*Verify that the account exists */
  23. if @balance is NULL
  24. begin
  25.   declare @err varchar(80)
  26.   select @err =  "Account " + convert(varchar(8), @acct) + " does not exist"
  27.   raiserror 21000 @err
  28.   rollback transaction
  29.   return
  30. end
  31.  
  32. /* Check for sufficient funds */
  33. if @balance + @delta < 0
  34. begin
  35.   raiserror 21001 "Insufficient funds."
  36.   rollback transaction
  37.   return
  38. end
  39.  
  40. /*
  41. **update account and teller and transid
  42. */
  43.  
  44. update account
  45. set balance = balance + @delta
  46. where number = @acct
  47.  
  48. update teller
  49. set balance = balance + @delta
  50. where number = @teller
  51.  
  52. update branch
  53. set balance = balance + @delta
  54. where number = @branch
  55.  
  56. insert history
  57. values(@acct,@teller,@branch,@balance,@delta,@pid,@transid,"Hi Mom")
  58.  
  59. select @outbuff
  60.  
  61. commit transaction
  62. go
  63.  
  64.  
  65.