clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2591659 fiddles created (45711 in the last week).

/* This should be your whole question: I'm passing parameters with multiple values like ( 2,3,4) and column having same like that like ( 2,3,5,6,7,8) I want get result = 2,4 record from column Though I think you meant you want the result = 2,3 ? */ CREATE TABLE dbo.BadIdeas(BadIdeaID int, BadColumn varchar(max)); INSERT dbo.BadIdeas(BadIdeaID, BadColumn) VALUES (1, '2,3,5,6,7,8'), -- two matches (2, '5,6'), -- no matches (3, '2,7'); -- 1 match
3 rows affected
 hidden batch(es)


DECLARE @parameter varchar(max) = '2,3,4'; -- if SQL Server 2017+ SELECT b.BadIdeaID, SQL2017result = STRING_AGG(sc.value, ',') FROM dbo.BadIdeas AS b CROSS APPLY STRING_SPLIT(b.BadColumn, ',') AS sc INNER JOIN STRING_SPLIT(@parameter, ',') AS sp ON sc.Value = sp.Value GROUP BY b.BadIDeaID; -- if SQL Server 2016+ ;WITH agg AS ( SELECT b.BadIdeaID, sc.value FROM dbo.BadIdeas AS b CROSS APPLY STRING_SPLIT(b.BadColumn, ',') AS sc INNER JOIN STRING_SPLIT(@parameter, ',') AS sp ON sc.Value = sp.Value ) SELECT BadIdeaID, SQL2016result = STUFF( ( SELECT ',' + value FROM agg AS a WHERE a.BadIdeaID = agg.BadIdeaID FOR XML PATH, TYPE ).value(N'.[1]', N'varchar(max)'), 1, 1, '') FROM agg GROUP BY BadIdeaID;
BadIdeaID SQL2017result
1 2,3
3 2
BadIdeaID SQL2016result
1 2,3
3 2
 hidden batch(es)