日期:2014-05-17  浏览次数:20551 次

请大虾帮忙看看下面存储过程,有什么语法错误
Create Procedure SP_BindCoupons(
@actID INT, --活动ID
@cardNo int, --卡号
@count10 int, --生成的10元券数量
@count20 int, --生成的10元券数量
@count30 int --生成的10元券数量
)
AS
DECLARE @winCount10 int,
        @winCount20 int,
        @winCount30 int,
        @nextWinNo int,
        @tempValue int,
        @errorValue nvarchar(100),
        @errorCode int
    Begin
           Set NOCOUNT ON;
           Set XACT_ABORT ON;
           begin tran bindCoupon  --开始事务bindCoupon 
           --查询该活动可生成的10元券数量
select @winCount10=(wc.WinningEnd-wc.NextWinningNo),@nextWinNo=wc.NextWinningNo from Winning_Config wc where wc.ID=@actID and wc.WinningType=10
Set @tempValue=1
if(@winCount10>=@count10)
begin 
--绑定10元券
while(@tempValue<=@count10)
begin
INSERT INTO [Winning_List]([ActivityID],[WinningNo],[WinningType],[AccID],[Status],[CardNo],[UseDate]
,[Cdate]
,[UseType])
 VALUES
(@actID,@nextWinNo+@tempValue,10,'',0,@cardNo,'1900-01-01 00:00:00.000',getdate(),null)

Set @tempValue=@tempValue+1

end
--修改代金券的下一个券号
UPDATE [Winning_Config] SET [NextWinningNo] = @nextWinNo+@winCount10 WHERE ID=@actID
end
else
begin
Set @errorValue+='该活动10元券数量不足;'
Set @errorCode=1
end  
end   

--查询该活动可生成的20元券数量
select @winCount20=(wc.WinningEnd-wc.NextWinningNo),@nextWinNo=wc.NextWinningNo from Winning_Config wc where wc.ID=@actID and wc.WinningType=20
Set @tempValue=1
if(@winCount20>=@count20)
begin 
--绑定20元券
while(@tempValue<=@count20)
begin
INSERT INTO [Winning_List]([ActivityID],[WinningNo],[WinningType],[AccID],[Status],[CardNo],[UseDate]
,[Cdate]
,[UseType])
 VALUES
(@actID,@nextWinNo+@tempValue,20,'',0,@cardNo,'1900-01-01 00:00:00.000',getdate(),null)

Set @tempValue=@tempValue+1
end
--修改代金券的下一个券号
UPDATE [Winning_Config] SET [NextWinningNo] = @nextWinNo+@winCount20 WHERE ID=@actID
end
else
begin
Set @errorValue+='该活动20元券数量不足;'
Set @errorCode=1
end  
end   
 
            
--查询该活动可生成的30元券数量
select @winCount30=(wc.WinningEnd-wc.NextWinningNo),@nextWinNo=wc.NextWinningNo from Winning_Config wc where wc.ID=@actID and wc.WinningType=30
Set @tempValue=1
if(@winCount30>=@count30)
begin 
--绑定30元券
while(@tempValue<=@count30)
begin
INSERT INTO [Winning_List