TRY THIS: for the permanent and flexible solution
Create function Split
to achieve this requirement and future use also
CREATE FUNCTION dbo.Split(@sep char(1), @s varchar(512))
RETURNS table
AS
RETURN (
WITH Pieces(pn, start, stop) AS (
SELECT 1, 1, CHARINDEX(@sep, @s)
UNION ALL
SELECT pn + 1, stop + 1, CHARINDEX(@sep, @s, stop + 1)
FROM Pieces
WHERE stop > 0
)
SELECT pn,
SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS s
FROM Pieces
)
Your table and values
DECLARE @SW_TBL_KEYWORD TABLE(Keyword VARCHAR(500))
INSERT INTO @SW_TBL_KEYWORD VALUES
('ATOP'),
('APMT'),
('RSND')
Logic to achieve your requirement
DECLARE @string VARCHAR(MAX)
SELECT @string='ATOP,APMT'
Split the comma separated value using function you have created and store in table variable or in temporary table
DECLARE @tmp_filter TABLE(keyword VARCHAR(500))
INSERT INTO @tmp_filter
SELECT s FROM dbo.Split(',', @string)
Join the filter table with actual table using Like
but after seeing your filter and actual values I think you want the exact match instead of partial using like
SELECT t1.*
FROM @SW_TBL_KEYWORD t1
INNER JOIN @tmp_filter t2 ON t1.Keyword LIKE ('%' + t2.keyword + '%')
For exact match we can change the join with below line
INNER JOIN @tmp_filter t2 ON t1.Keyword = t2.keyword
NOTE: this is long term solution and useful for the other similar tasks. If you were using SQLSERVER2016 or newest
then you coluld use STRING_SPLIT
function instead of creating user defined function.