Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect with IN and Like
    primarykey
    data
    text
    <p>I have a very interesting problem. I have an SSRS report with a multiple select drop down. The drop down allows to select more than one value, or all values. All values is not the problem. </p> <p>The problem is 1 or the combination of more than 1 option</p> <p>When I select in the drop down 'AAA' it should return 3 values: 'AAA','AAA 1','AAA 2'</p> <p>Right now is only returning 1 value. </p> <p><strong>QUESTION:</strong></p> <p>How can make the IN statement work like a LIKE?</p> <pre><code>The Drop down select SELECT '(All)' AS team, '(All)' AS Descr UNION ALL SELECT 'AAA' , 'AAA' UNION ALL SELECT 'BBB' , 'BBB' Table Mytable ColumnA Varchar(5) Values for ColumnA 'AAA' 'AAA 1' 'AAA 2' 'BBB' 'BBB 1' 'BBB 2' SELECT * FROM Mytable WHERE ColumnA IN (SELECT * FROM SplitListString(@Team, ','))) Split function CREATE FUNCTION [dbo].[SplitListString] (@InputString NVARCHAR(max), @SplitChar CHAR(1)) RETURNS @ValuesList TABLE ( param NVARCHAR(MAX) ) AS BEGIN DECLARE @ListValue NVARCHAR(max) DECLARE @TmpString NVARCHAR(max) DECLARE @PosSeparator INT DECLARE @EndValues BIT SET @TmpString = LTRIM(RTRIM(@InputString)); SET @EndValues = 0 WHILE (@EndValues = 0) BEGIN SET @PosSeparator = CHARINDEX(@SplitChar, @TmpString) IF (@PosSeparator) &gt; 1 BEGIN SELECT @ListValue = LTRIM(RTRIM(SUBSTRING(@TmpString, 1, @PosSeparator -1 ))) END ELSE BEGIN SELECT @ListValue = LTRIM(RTRIM(@TmpString)) SET @EndValues = 1 END IF LEN(@ListValue) &gt; 0 BEGIN INSERT INTO @ValuesList SELECT @ListValue END SET @TmpString = LTRIM(RTRIM(SUBSTRING(@TmpString, @PosSeparator + 1, LEN(@TmpString) - @PosSeparator))) END RETURN END </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload