declare @TeacherID  numeric
  declare  @bT datetime
declare    @eT  datetime
declare   @bWordType  numeric-- 0:语音,1:文字 2:所有
declare   @bPublic  numeric--bPublic:1 公开,0:个别
    
 declare @AllRen  numeric
  declare @TingRen numeric 
 declare @MsgID   numeric(30)
declare @LeaveTime datetime
declare @WordType  numeric
declare @Words  nvarchar(300)
declare @RecvID numeric
 
select @TeacherID=100000001
select @bT='2007-7-18'
select @eT='2007-7-18'
select @bWordType=0
select @bPublic=1
 Create Table  #AA(MessageId  numeric(30) not null ,LeaveTime datetime ,WordType numeric,Words varchar(300),ShouTingRen numeric ,bPublic numeric )
if @bPublic=1
  begin
   declare Cur1 CURSOR for  select  MessageID,LeaveTime,WordType,Words,1 as bPublic ,RecvID  from SchoolMsgInfo where Publishman=@TeacherID and LeaveTime>=@bT and LeaveTime<=@eT  and  WordType=0
   open Cur1
     FETCH FROM Cur1 into 
      @MsgID,@LeaveTime,@WordType,@Words,@bPublic,@RecvID
     
   WHILE @@FETCH_STATUS=0
beginselect  @AllRen=Count(*) from students where ClassID=@RecvID 
     select @TingRen=Count(*) from SchoolMessage where  MessageID=@MsgID
     
     insert into #AA values(@MsgID,@LeaveTime,@WordType,@Words,@TingRen,@bPublic)
      
FETCH FROM Cur1 into 
      @MsgID,@LeaveTime,@WordType,@Words,@bPublic,@RecvID
end
 close Cur1--这里已经关闭
 Print 'hello' 
  end
else
  begin   print @bPublic
  end
select * from #AA
drop table #AA
GO

解决方案 »

  1.   

    要加這一句就沒了吧
    DEALLOCATE cur1
      

  2.   

    雖然關閉了,但是沒有釋放。在close Cur1下一行加上DEALLOCATE Cur1DEALLOCATE
    移除資料指標參考。當最後一個資料指標參考解除配置之後,構成此資料指標的資料結構就會被 Microsoft&reg; SQL Server&#8482; 釋放。
      

  3.   

    資料指標名稱被關聯到某個資料指標之後,此名稱就不能被相同範圍 (GLOBAL 或 LOCAL) 的另一個資料指標所用,直到這個資料指標被解除配置為止。