create procedure proc_takeMoney
@cadrID varchar(20),
@transMoney money,
@transType varchar(max),
@pass varchar(20)=null
as
declare @balance money
print'交易正在进行,请稍后。。。'
if(@transType='支取')
begin
if(@pass =(select pass from cardInfo where cardID =@cadrID))
begin
if(@transMoney<(select balance from cardinfo where cardID =@cadrID ))
begin
insert into tradeInfo(cardID ,tradeType ,tradeMoney)
values(@cadrID ,@transType,@transMoney)
update cardInfo set balance =balance -@transMoney
where cardID =@cadrID print' 交易成功'+@transType+'
金额:'+convert(varchar(20),@balance)+'RMB'
SELECT @balance =balance from cardInfo where
cardID =@cadrID print'卡号'+@cardid+'余额:'
+Convert(varcahr(20),@BAKANCE)+'RMB'
END
ELSE
PRINT'交易失败,,您的余额不足,,'
end
else
print'交易成功,,'+@transType+' 金额:'
+Convert(varchar(20),@tranMoney)+'RMB'
select @balance =balance from cardInfo
where cardID =@cadrID
print'卡号 :'+@cardid+'余额:'+convert
(varchar(20),@balance)+' RMB'
end
go
-------------------------
declare @cardid varchar(20)
select @cardid =Cardid from userInfo as u
inner join cardInfo as c on
u.customerID =c.customerID
where customerName='张三'
exec proc_takeMoney @cardId,300,'支取','123456'
go
declare @cardid varchar(20)
select @cardid =cardid
from userInfo as u inner join cardInfo as c on u.customerID =C.customerID
where customerName=' 李四'
exec proc_takeMoney @cardid,500,'存入'
go
错误消息
消息 137,级别 15,状态 2,第 1 行
必须声明标量变量 "@transType"。
------解决方案--------------------
点结贴,然后》。。。。你应该会了吧