add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tblTest
(
RecID int,
Column1 varchar(100)
);

INSERT INTO tblTest(RecId, Column1) VALUES
(1, '1,2,3,4,5'),
(2, '6,7,8,9,10');

Declare @RecId int = 1,
@Str_RemoveNumbers Varchar(MAX) = '2, 4, 20';

WITH CTE1 AS
(
SELECT RecID, [Value]
FROM tblTest
CROSS APPLY STRING_SPLIT(Column1, ',')
WHERE RecID = @RecId
), CTE2 AS
(
SELECT RecID, STRING_AGG([Value], ',') As Col1
FROM CTE1
WHERE [Value] NOT IN(
SELECT TRIM([Value])
FROM STRING_SPLIT(@Str_RemoveNumbers, ',')
)
GROUP BY RecID
)


UPDATE t
SET Column1 = Col1
FROM tblTest As t
JOIN CTE2
ON t.RecId = CTE2.RecId
RecID Column1
1 1,3,5
2 6,7,8,9,10