-----------------------创建存钱、取钱、查询的存储过程-------------------------
use bankDB
go
if exists (select * from sysobjects where name='proc_takemoney')
begin
drop proc proc_takemoney
end
go
create proc proc_takemoney
@mycardID varchar(50),
@pass varchar(10),
@transType varchar(10),
@transMoney money,
@IsReportLoss varchar(10)
as
print '---------------------------------------------'
print ' 欢迎来到中国建设银行 '
print ' Welcome To China Construction Bank '
print '---------------------------------------------'
insert into transInfo(cardID,transType,transMoney)
values(@mycardID,@transType,@transMoney)
select transDate as '交易日期',cardID as'卡号',transType as'交易类型',transMoney as'交易金额',remark as'备注'
from transInfo where cardid=@mycardid
if(@pass=(select pass from cardinfo where cardid=@mycardid))
begin
if((select IsReportLoss from cardInfo where cardID=@mycardID)='否')
begin
declare @balance float
if(@transType='存入')
begin
if(@transMoney>1)
begin
update cardInfo set balance=balance+@transMoney where cardID=@mycardID
--set @errorsum=@errorsum+@@error
print '交易成功!存入金额'+convert(varchar(10),@transMoney)
select @balance=balance from cardInfo where cardid=@mycardid
print'卡号'+@mycardID+' '+'余额'+convert(varchar(10),@balance)
end
else
begin
print '交易失败!金额不足!'
select @balance=balance from cardInfo where cardid=@mycardid
print'卡号'+@mycardID+' '+'余额'+convert(varchar(10),@balance)
end
end
else
begin
if(@transType='支取')
begin
if(@balance-@transMoney>=1)
begin
update cardInfo set balance=balance-@transMoney where cardID=@mycardID
print '交易成功!支取金额'+convert(varchar(10),@transMoney)
select @balance=balance from cardInfo where cardid=@mycardid
print'卡号'+@mycardID+' '+'余额'+convert(varchar(10),@balance)
end
end
else
begin
print '交易失败!金额不足!'
select @balance=balance from cardInfo where cardid=@mycardid
print'卡号'+@mycardID+' '+'余额'+convert(varchar(10),@balance)
end
end
end
else
begin
print '您的账号已挂失,不能取款'
end
end
else
begin
print '您的账号或密码输入错误,请重新输入'
end
go
******
存钱状况良好,可取钱时会出现超支的情况,不显示交易失败的那些信息,还有不管选择是否挂失它都默认为否,请问我该把哪里做下修改?最好不要改动的面目全非