ALTER PROCEDURE [dbo].[sp_tmp_ad_GetIDS] 
(
@TaskID int,
@sid int,
@n int
)
AS
BEGIN    
    declare @table table(id int,keyword nvarchar(200))
declare @keywordid int
declare @gettime datetime
select @gettime=getdate()
update dbo.map_job_task set gettime=@gettime where  TaskID=@TaskID and sid=@sid 
select @keywordid=keywordid from dbo.map_job_task where TaskID=@TaskID and sid=@sid and gettime=@gettime
update dbo.map_job_task set keywordid=keywordid+@n where  TaskID=@TaskID and sid=@sid and gettime=@gettime
if(@@rowcount>0)
begin
insert into @table 
select top(@n) id,keyword from dt_keyword where id>@keywordid and tag is null order by id
select * from @table
end
else
exec sp_tmp_ad_GetIDS @TaskID,@sid,@n
--sp_tmp_ad_GetIDS
END