SET @Keywords=REPLACE(@Keywords,",", ",") SET @Keywords=REPLACE(@Keywords,";", ",") SET @Keywords=RTRIM(LTRIM(@Keywords))
SET @I=CHARINDEX(",", @Keywords)
WHILE @I>=1 BEGIN SET @Keyword=LEFT(@Keywords, @I-1) INSERT INTO DetailKeywords (DetailID, Keyword) VALUES(@DetailID, @Keyword) SET @Keywords=SUBSTRING(@Keywords, @I+1,LEN(@Keywords)-@I) SET @I=CHARINDEX(",", @Keywords) END
IF @Keywords<>"" INSERT INTO DetailKeywords (DetailID, Keyword) VALUES(@DetailID, @Keywords) GO
SELECT @Keywords=Keywords FROM Details WHERE ItemID=@DetailID
IF @Keywords<>"" BEGIN SELECT DISTINCT d.ItemID, d.Subject, d.ItemFile FROM Details d RIGHT OUTER JOIN DetailKeywords k ON k.DetailID=d.ItemID WHERE d.ItemID <> @DetailID AND @Keywords LIKE "%"+k.Keyword+"%" END GO