--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
验证身份后,给他给配桌子。要返回成功承包的桌子数(房间剩余桌子不够,则返回承包到部分数量)。主要存储过程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
用ASP调用的时候,A的返回参数是正确的。但是B也执行,也返回正确参数,就是不分配桌子。不返回分配了多少