在存储过程A中运行存储过程B,返回的是执行B成功时的返回值,但中间的过程并不执行。如果在查询分析器里面单独执行B,一切正常。这是什么原因啊!高人给解答一下,谢谢!

解决方案 »

  1.   

    大概意思就是,用户选择承包几个桌子(或者房间之类),选择个数,扣费。
    验证身份后,给他给配桌子。要返回成功承包的桌子数(房间剩余桌子不够,则返回承包到部分数量)。主要存储过程B不是人写的,是调用。--存储A
    CREATE PROCEDURE usp_A
    @roomID int,
    @ComID int,
    @SumDesk intASDECLARE @nErrorResult int ,@nCountRow int
    declare @tt varchar(50)
    set @nCountRow = 0
    --其他判断成功后,调用usp_BExec @nCountRow =  usp_B @roomID,@ComID,@SumDesk,@nErrorResult output  --select @nCountRow
    --select @nCountRow

    --print @nCountRow
    --print @nErrorResult
    RETURN @nErrorResultGO/////////////////////////////////////////////////////////////--存储B
    CREATE   proc usp_B
    @nRoomId int,
    @nCommunityId int,
    @nDeskCount int,
    @nErrorResult int output
    as
    declare @nAllocatedDesk int
    declare @nMaxAllocateNum int
    declare @nMaxDeskNum  int
    declare @dtStartTime_inner datetime
    declare @dtEndTime_inner datetime
    declare @dtCurTime datetime
    declare @nAllocatedCount int select @nMaxDeskNum = DeskCount from YHLogonData.dbo.GameRoomInfo where RoomId = @nRoomId
    set @nMaxAllocateNum = 10
    set @nAllocatedCount = 0
    set @dtCurTime = Getdate() if @@error = 0
    begin
    --Acquare successfully visitor lock and continues
    --delete all comminity desks which were expired!
    declare desk_cursor cursor for
    select desk_id, terminate_time from CommunityDesk
    where room_id = @nRoomId order by desk_id
    open desk_cursor
    fetch desk_cursor into @nAllocatedDesk, @dtEndTime_inner
    while @@fetch_status = 0
    begin
    if @dtCurTime > @dtEndTime_inner
    begin
    delete from CommunityDesk
    where desk_id = @nAllocatedDesk
    end
    fetch next from desk_cursor into @nAllocatedDesk, @dtEndTime_inner
    end
    close desk_cursor
    deallocate desk_cursor

    --create a tempory table to store index of desks which still wasn't allocated
    create table #RemainDesks(desk_index int)
    while @nMaxDeskNum > 0
    begin
    insert into #RemainDesks values(@nMaxDeskNum)
    set @nMaxDeskNum = @nMaxDeskNum - 1
    end
    --declar a cursor to read index of desks which was allocated
    declare desk_cursor cursor for
    select desk_id from CommunityDesk  
    where room_id = @nRoomId order by desk_id
    open desk_cursor
    fetch desk_cursor into @nAllocatedDesk
    while @@fetch_status = 0
    begin
    delete from #RemainDesks where @nAllocatedDesk = desk_index
    fetch next from desk_cursor into @nAllocatedDesk
    end
    close desk_cursor
    deallocate desk_cursor

    --select some desks which were not still allocated
    declare desk_cursor cursor for
    select desk_index from #RemainDesks order by desk_index
    open desk_cursor
    fetch desk_cursor into @nAllocatedDesk
    while @@fetch_status = 0 and @nAllocatedCount < @nDeskCount
    begin
    insert into CommunityDesk values(@nRoomId, @nAllocatedDesk, @nCommunityId, getdate(), getDate())
    set @nAllocatedCount = @nAllocatedCount + 1
    fetch next from desk_cursor into @nAllocatedDesk end
    close desk_cursor
    deallocate desk_cursor set @nErrorResult = 999
    -- Release lock

    end else
    begin
    set @nErrorResult = 1
    end return @nAllocatedCount
    GO
      

  2.   

    在查询分析器里面,无论执行A,或者B,都正确。
    用ASP调用的时候,A的返回参数是正确的。但是B也执行,也返回正确参数,就是不分配桌子。不返回分配了多少
      

  3.   

    --select @nCountRow如果去掉注释再从所选表中得不到数据就不清楚了.
      

  4.   

    结贴,发现问题了。十分感谢关注我的哥们!hrb133yqq() 大哥,一句话点醒梦中人啊!!!是数据有问题,程序和存储过程都对!