存储过程执行有误,请进来看具体情况
/************************购物车生成订单并支付[gen_order_cart]******************/alter procedure gen_order_cart@UserName varchar(14)as declare @balance float, --用户余额 @pay float, --购物车总价 @flag1 int, --操作成功标志 @flag2 int, @flag3 int; --获取账户余额 select @balance=Balance from Member where UserName=@UserName; if @balance is null begin print '账户余额为空'; return; end --获取购物车总价 select @pay=sum(TmpPrice) from (select TmpPrice from Cart,TmpDetail where Cart.TmpID=TmpDetail.TmpID and UserName=@UserName) as T; if @pay is null begin print '购物车为空'; return; end --判断账户余额是否足以支付购物车中项目 if @balance<@pay begin print '余额不足以支付'; return; end --删除购物车项目并扣除账户余额,同时添加订单记录 set @flag1=1; set @flag2=1; set @flag3=1; BEGIN TRANSACTION --删除购物车项目 delete from Cart where UserName=@UserName; print '用户['+@UserName+']购物车已经清空'; if @@rowcount=0 set @flag1=0; --添加订单记录 insert into "Order" (UserName,TmpID,PayTime) (select UserName,TmpID,getdate() from Cart where UserName=@UserName); print '用户['+@UserName+']购买记录已经添加'; if @@rowcount=0 set @flag2=0; --扣除账户余额 update Member set Balance=(Balance-@pay) where UserName=@UserName; print '用户['+@UserName+']余额已经扣除'; if @@rowcount=0 set @flag3=0; --处理操作结果标识 if @flag1=0 or @flag2=0 or @flag3=0 ROLLBACK TRANSACTION; else COMMIT TRANSACTION;go
--添加订单记录 insert into "Order" (UserName,TmpID,PayTime) (select UserName,TmpID,getdate() from Cart where UserName=@UserName); print '用户['+@UserName+']购买记录已经添加'; if @@rowcount=0 set @flag2=0;
delete from Cart where UserName=@UserName; print '用户['+@UserName+']购物车已经清空'; if @@rowcount=0 set @flag1=0;
[解决办法]
JF!