IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_save_selects_into_datalinker]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_save_selects_into_datalinker]
GO
create procedure [dbo].[mps_save_selects_into_datalinker](
@cmpid int,
@useruid int,
@objids varchar(max)
) as
begin
set nocount on
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
declare @t table(dpid bigint) 
declare @i int,@curInd int,@strlen int,@tmps varchar(100) ,@srcs varchar(max)
set @srcs = @objids 
select @curInd=1,@strlen=LEN(@srcs) 
while (@curInd<=@strlen) 
begin 
select @i=charindex(',',@srcs,@curInd) 
if (@i>0) 
begin 
select @tmps=SUBSTRING(@srcs,@curInd,@i-@curInd) 
set @curInd=@i+1 
end else if (@curInd<=@strlen) 
begin 
select @tmps=SUBSTRING(@srcs,@curInd,@strlen-@curInd+1) 
set @curInd=@strlen+1 
end 
if (@tmps>'') insert into @t(dpid) values(convert(bigint,@tmps)) 
end
delete datalinker where useruid=@useruid 
insert into datalinker(useruid,objid) select @useruid , dpid from @t 
select 'ok' result 
set nocount off
end