有以下可能
1、游标未关闭和释放的情况下又执行了游标(大多数是这样)当用完游标时应关闭和释放,摸板如下
DECLARE CURNAME CURSOR FOR ...
OPEN CURNAME
//其他语句
CLOSE CURNAME
DEALLOCATE CURNAME2、存储过程的游标名和触发器的游标名相同了(情况较少)
该成不同的游标名
注:如果满意要给分呀!
1、游标未关闭和释放的情况下又执行了游标(大多数是这样)当用完游标时应关闭和释放,摸板如下
DECLARE CURNAME CURSOR FOR ...
OPEN CURNAME
//其他语句
CLOSE CURNAME
DEALLOCATE CURNAME2、存储过程的游标名和触发器的游标名相同了(情况较少)
该成不同的游标名
注:如果满意要给分呀!
----------该存储过程用于生成T_RMSysData表的数据-----------------CREATE PROCEDURE GetRMSysData
AS
declare @date datetime,@class char(1),@booked int,@noshow int,@goshow1 int,@goshow2 int,@goshow21 int,@goshow22 int,@actual int,@ActualbyClass int,@BookedbyClass int
declare @datenum int,@flightnum int,@fln char(4),@upgrade int,@missconnection int,@denied int
declare @origin char(3),@destination char(3),@pnr varchar(6),@flytime char(5)
declare @datetime datetime,@datetime1 datetime,@datetime2 datetimecreate table #tb1(class char(1),booked int,noshow int,goshow1 int,goshow2 int,actual int)--------以下根据日期定义游标----------------declare date_cursor cursor for select distinct fdt from cj_pnrp
open date_cursor -----打开游标
fetch next from date_cursor into @date ------从游标取出日期
while @@fetch_status=0 ------循环
begin
----------------以下根据航班号定义游标--------------------------- declare fln_cursor cursor for select distinct fln from cj_pnrp where fdt=@date
open fln_cursor --------打开游标
fetch next from fln_cursor into @fln --------从游标取出航班号
while @@fetch_status=0 --------循环
begin
declare od_cursor cursor for select distinct bpt,opt from cj_pnrp where fdt=@date and fln=@fln
open od_cursor
fetch next from od_cursor into @origin,@destination
while @@fetch_status=0
begin
select @flytime=left(StartTime,2)+':'+right(StartTime,2) from t_zhflight where flight=@fln and startcity=@origin and endcity=@destination
select @datetime=@date+' '+@flytime
select @datetime1=dateadd(mi,-90,@datetime) -----飞机离港前90分钟
select @datetime2=dateadd(mi,-30,@datetime) -----飞机离港前30分钟 declare class_cursor cursor for select distinct idp from cj_pnrp where fdt=@date and fln=@fln
open class_cursor
fetch next from class_cursor into @class
while @@fetch_status=0
begin
declare pnr_cursor cursor for select distinct ipn from cj_pnrp where fdt=@date and fln=@fln and bpt=@origin and opt=@destination and idp=@class
open pnr_cursor
fetch next from pnr_cursor into @pnr
while @@fetch_status=0
begin ---------------以下剔除bidt表里面的重复数据------------------------------ if exists(select * from Tempdb..sysobjects where id=object_id( 'tempdb..#tmp') and type='U')
drop table #tmp
set nocount on
select top 1 * into #tmp from bidt where flydate=@date and flight=@fln and seatclass=@class and startcity=@origin and endcity=@destination and recordno=@pnr
--------统计定座数
select @BookedbyClass=count(*) from #tmp where flydate=@date and seatclass=@class and flight=@fln and issuedate<=@datetime1 ----各舱位定座数
select @booked=count(*) from #tmp where flydate=@date and flight=@fln and issuedate<=@datetime1 ----总定座数
-------统计GOSHOW2数据(其中@goshow21是航班结载前90~30的数据;@goshow22是航班结载前30内的数据,两部分的和就是GOSHOW2数据)
select @goshow21=count(*) from #tmp where flydate=@date and seatclass=@class and flight=@fln and issuedate>@datetime1 and issuedate<=@datetime2
if exists(select * from T_RMSysData where flydate=@date and class=@class and planeno=@fln)
select @goshow22=goshow2,@goshow1=goshow1,@upgrade=upgrading,@missconnection=missconnect,@denied=denied from T_RMSysData where flydate=@date and class=@class and planeno=@fln
else
select @goshow22=0,@goshow1=0,@upgrade=0,@missconnection=0, @denied=0
select @goshow2=@goshow21+@goshow22
---------统计实际承运人数
select @ActualbyClass=count(*) from cj_pnrp where fdt=@date and fln=@fln and idp=@class -----各舱位人数
select @actual=count(*) from cj_pnrp where fdt=@date and fln=@fln -----总人数
--------统计NOSHOW数据--------------
select @noshow=@goshow1+@goshow2+@booked-@actual set nocount on
insert into #tb1 values(@class,@bookedbyClass,@noshow,@goshow1,@goshow2,@actualbyClass)
fetch next from pnr_cursor into @pnr
end
close pnr_cursor
deallocate pnr_cursor fetch next from class_cursor into @class
end
close class_cursor
deallocate class_cursor fetch next from od_cursor into @origin,@destination
end
close od_cursor
deallocate od_cursor ---------取下个航班号
fetch next from fln_cursor into @fln
end
close fln_cursor -----------关闭航班号游标
deallocate fln_cursor -----------释放航班号游标 -------取出下一个日期 fetch next from date_cursor into @date
endset nocount off
select * from #tb1close date_cursor ----------关闭日期游标
deallocate date_cursor ----------释放日期游标
GO
1.服务器: 消息 2801,级别 16,状态 1,过程 GetRMSysData,行 107
对象 'GetRMSysData' 的定义在编译后已有更改。
你看看你所定义的参数在赋予值时类型是否相一致;2.服务器: 消息 16915,级别 16,状态 1,过程 GetRMSysData,行 15
名为 'date_cursor' 的游标已存在。
改个名试试。