Search code examples
sql-serverreporting-servicesssrs-2008sql-like

SQL Server Selecting multiple LIKE values in Report Builder


I have a report where I'm trying to allow the user to select multiple predetermined LIKE values from a drop down list for their results in report builder. Is there a way I can do this? I have tried to use LIKE IN() but those two keywords don't seem to work together. Here is the code that I have. The code I have only works if I select one option.

DECLARE @Warehouse nvarchar(10)
DECLARE @Location nvarchar(10)
SET @Warehouse = 'Warehouse1'
SET @Location = 'IB'

SELECT Part
, Tag
, CurrentLocation AS 'Location'
, TotalQty
, DateTimeCreated 
, datediff(hour, DateTimeCreated, getdate()) AS 'Hours in Location'
, User AS 'Last User'
FROM table1
WHERE datediff(hour, DateTimeCreated, getdate())>=1
AND Warehouse IN(@Warehouse)
AND(CurrentLocation LIKE '%' + @Location + '%')
ORDER BY 'Hours in Location' DESC, CurrentLocation

Solution

  • Thank you for your responses. This is what I ended up doing that fixed my problem.

    SELECT Part
    , Tag
    , CurrentLocation AS 'Location'
    , TotalQty
    , DateTimeCreated 
    , datediff(hour, DateTimeCreated, getdate()) AS 'Hours in Location'
    , User AS 'Last User'
    FROM table 1
    WHERE datediff(hour, DateTimeCreated, getdate())>=1
    AND Warehouse in (@Warehouse)
    AND LEFT(CurrentLocation,2) IN(@Location)
    ORDER BY 'Hours in Location' DESC, CurrentLocation