0

Based on my question SSRS selecting results based on comma delimited list

Is it possible to do this, but instead of doing this as a an EQUALS, can it be done as below?
WHERE value like 'abc%','def%'

One thing to note is that the % is not included in the list.

peterbonar
  • 559
  • 3
  • 6
  • 24

1 Answers1

0

One option is to split the passed in SSRS variable (CSV) into a table and join on that

DECLARE @tab TABLE (Col1 NVARCHAR(200))
INSERT INTO @tab (Col1)
VALUES (N'abc'),(N'def'),(N'xyz'),(N'nop'),(N'ghi'),(N'lmn')

DECLARE @substrings NVARCHAR(200) = 'abc,def,ghi'

;WITH cteX
AS(   --dynamically split the string
    SELECT Strings = y.i.value('(./text())[1]', 'nvarchar(4000)')
    FROM 
    ( 
    SELECT x = CONVERT(XML, '<i>' 
        + REPLACE(@substrings, ',', '</i><i>') 
        + '</i>').query('.')
    ) AS a CROSS APPLY x.nodes('i') AS y(i)
) 
SELECT
    T.*
FROM @tab   T
INNER JOIN cteX X ON X.Strings = T.Col1

gives the following result

enter image description here

Mazhar
  • 3,797
  • 1
  • 12
  • 29