ALTER proc  [dbo].[调用流程]
@BudgetType char(2)
,@Year numeric(4)
,@orgid nchar(10)
as
begin --1
declare @Productid varchar(8)
declare CallPrm Cursor for --建立游标
select ProductID from Product where productlevel is not null
or rtrim(ltrim((productlevel))) <>''
order by ProductLevel,Productid
for read only open CallPrm FETCH NEXT FROM CallPrm INTO @Productid
While @@fetch_status=0
begin --2
exec  成本计算主流程 @budgettype,@Productid,@year,1,@orgid
PRINT 'MONTH 1 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,2,@orgid
PRINT 'MONTH 2 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,3,@orgid
PRINT 'MONTH3 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,4,@orgid
PRINT 'MONTH4 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,5,@orgid
PRINT 'MONTH5 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,6,@orgid
PRINT 'MONTH6 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,7,@orgid
PRINT 'MONTH7 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,8,@orgid
PRINT 'MONTH8 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,9,@orgid
PRINT 'MONTH9 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,10,@orgid
PRINT 'MONTH10 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,11,@orgid
PRINT 'MONTH11 SUCCESS.'
exec  成本计算主流程 @budgettype,@Productid,@year,12,@orgid
PRINT 'MONTH12 SUCCESS.'
begin --3
FETCH NEXT FROM CallPrm INTO @Productid
end --3
end --2
close CallPro       --关闭游标
DEALLOCATE CallPro     --注销游标
 
end                                                                                   --1
这是一个存储过程,里面使用了游标来调用存储过程,但是执行提示错误如下:
Msg 16915, Level 16, State 1, Procedure 调用流程, Line 10
A cursor with the name 'CallPrm' already exists.
Msg 16905, Level 16, State 1, Procedure 调用流程, Line 15
The cursor is already open.
Msg 16916, Level 16, State 1, Procedure 调用流程, Line 50
A cursor with the name 'CallPro' does not exist.
Msg 16916, Level 16, State 1, Procedure 调用流程, Line 51
A cursor with the name 'CallPro' does not exist.我看着四条提示,前两条和后两条意思是完全相反的呀,大家帮忙看看是怎么回事。谢谢

解决方案 »

  1.   

    declare @Productid varchar(8) 
    declare CallPrm Cursor for --建立游标 
    select ProductID from Product where productlevel is not null 
    or rtrim(ltrim((productlevel))) <>'' 
    order by ProductLevel,Productid 
    for read only 
    建立游标
    open CallPrm FETCH NEXT FROM CallPrm INTO @Productid  --这里就是想用这个产品ID。循环调用存储过程“成本计算主流程 ”
      

  2.   

    close CallPro      --关闭游标 
    DEALLOCATE CallPro 
    游标名错了