home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
BENCHSQL.ZIP
/
TP1ONLY.SQL
< prev
next >
Wrap
Text File
|
1989-06-30
|
1KB
|
65 lines
use bench
go
create procedure tp1 @acct int, @teller int, @branch int, @delta int,
@transid int=0, @pid int=0, @inbuff char(100) as
declare @balance int
declare @outbuff char(200)
select @outbuff = "12345678901234567890123456789012345678901234567890"
+ "12345678901234567890123456789012345678901234567890"
+ "12345678901234567890123456789012345678901234567890"
+ "12345678901234567890123456789012345678901234567890"
begin tran
/*fetch current balance for account*/
select @balance = balance
from account
where number=@acct
/*Verify that the account exists */
if @balance is NULL
begin
declare @err varchar(80)
select @err = "Account " + convert(varchar(8), @acct) + " does not exist"
raiserror 21000 @err
rollback transaction
return
end
/* Check for sufficient funds */
if @balance + @delta < 0
begin
raiserror 21001 "Insufficient funds."
rollback transaction
return
end
/*
**update account and teller and transid
*/
update account
set balance = balance + @delta
where number = @acct
update teller
set balance = balance + @delta
where number = @teller
update branch
set balance = balance + @delta
where number = @branch
insert history
values(@acct,@teller,@branch,@balance,@delta,@pid,@transid,"Hi Mom")
select @outbuff
commit transaction
go