SQL Searching within comma delimited string

Split string UDF example you can find here

DECLARE @ChannelNumbers TABLE(Id INT, Channel VARCHAR(255))DECLARE @SearchString VARCHAR(255)SET @SearchString = '24'INSERT INTO @ChannelNumbers        ( Id, Channel )SELECT 1, '23,24' UNION ALLSELECT 3, '23' UNION ALLSELECT 3, '24' UNION ALLSELECT 5, '123' UNION ALLSELECT 6, '124'SELECT * FROM @ChannelNumbersWHERE @SearchString IN (SELECT ChannelId FROM dbo.SplitString(Id, Channel))

Notice that query does not return 124

Leave a Reply

Your email address will not be published. Required fields are marked *