Code CreateProcedure dbo.News_SimilarNews ( @topNvarchar(10), @idvarchar(100), @keywordsnvarchar(500) ) AS SET NOCOUNT ON declare@Iint declare@cint set@c=0 declare@Keywordnvarchar(50) declare@sqlvarchar(1000) set@sql='select top('+@topN+') pp_id,pp_sortid,pp_title from [pp_information] where pp_id<>'+@id+' and (' set@keywords=rtrim(ltrim(@keywords)) SET@I=CHARINDEX('', @Keywords) while@I>0 begin SET@Keyword=ltrim(rtrim(LEFT(@Keywords, @I-1))) if@c=0 set@sql=@sql+'[pp_keywords] like ''%'+@Keyword+'%''' else begin set@sql=@sql+' or [pp_keywords] like ''%'+@Keyword+'%''' end set@c=@c+1 SET@Keywords=SUBSTRING(@Keywords, @I+1,LEN(@Keywords)-@I) SET@I=CHARINDEX('', @Keywords) end if@c>0 set@sql=@sql+' or [pp_keywords] like ''%'+@keywords+'%''' else begin set@sql=@sql+'[pp_keywords] like ''%'+@keywords+'%''' end set@sql=@sql+') and pp_verify<>0 order by newid()' Exec(@sql)