52 lines
1.2 KiB
Transact-SQL
52 lines
1.2 KiB
Transact-SQL
CREATE procedure [dbo].[up_insert_channelbyAuto]
|
|
@Code int,
|
|
@World int
|
|
|
|
as
|
|
set nocount on
|
|
|
|
declare @i int
|
|
declare @last int
|
|
declare @current int
|
|
declare @minid int
|
|
declare @maxid int
|
|
set @i = 1
|
|
set @last = 0
|
|
set @current = 1
|
|
set @minid = 1
|
|
set @maxid = 1
|
|
|
|
select @last = ID from ChannelSeed where Last_Seed = 1 and WorldID = @World
|
|
select @maxid = MAX(ID) from ChannelSeed where WorldID = @World
|
|
select @minid = MIN(ID) from ChannelSeed where WorldID = @World
|
|
|
|
if @last = 0
|
|
begin
|
|
set @last = @minid
|
|
end
|
|
else
|
|
begin
|
|
set @last = @last+1
|
|
end
|
|
|
|
while @i <= 3
|
|
begin
|
|
|
|
if @last > @maxid
|
|
begin
|
|
set @last = @minid
|
|
end
|
|
|
|
insert into ChannelOption( Code, CH_Group, CH_Type, MinLevel, MaxLevel, CH_NUM, WorldID )
|
|
select @Code, CH_Group, CH_Type, MinLevel, MaxLevel, Current_Num, @World from ChannelSeed where ID = @last
|
|
|
|
select @current = Current_Num from ChannelSeed where ID = @last
|
|
update ChannelSeed set Current_Num = @current+1 where ID = @last
|
|
update ChannelSeed set Last_Seed = 0 where WorldID = @World
|
|
update ChannelSeed set Last_Seed = 1 where ID = @last
|
|
|
|
set @last = @last+1
|
|
set @i = @i+1
|
|
|
|
end
|
|
|