IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_ins_private_label]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_ins_private_label]
GO
CREATE procedure [dbo].[mps_ins_private_label]
@useruid int,
@tbtype varchar(10),
@objid int ,
@lbcids varchar(1000) 
as
begin
declare @s varchar(500)
declare @s1 varchar(100)
declare @i int 
set @s = @lbcids 
declare @t table(lbid int) 
while (@s>'')
begin
set @i=charindex(',',@s) 
if (@i>0)
begin
set @s1 = substring(@s,1,@i-1) 
set @s = substring(@s,@i+1,len(@s)-@i) 
end else 
begin
set @s1 = @s 
set @s = '' 
end 
if (@s1>'') 
insert into @t(lbid) values(convert(int,@s1)) 
end
insert into mps_label_private(lp_useruid,lp_lbcid,lp_type,lp_ctgid) 
select @useruid , lbid,@tbtype,@objid
from @t 
where (not exists(select * from mps_label_private where lp_useruid=@useruid and lp_lbcid=lbid and lp_type=@tbtype and lp_ctgid=@objid))

end