I have a report im creating in SSRS (2008) and the data for the report is coming from a stored procedure in MS SQL.
I want to have a multiple value parameter (done this
Create this function in your database:
USE [YourDatabase]
GO
/****** Object: UserDefinedFunction [dbo].[SplitListToTable] Script Date: 5/21/2018 8:13:29 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--==========================================================
-- Author: Gugg
-- Created: 2015-10-06
-- Description: Converts a delimited string into a table of values. Based heavily on code from this url:
-- https://social.msdn.microsoft.com/Forums/sqlserver/en-US/0ead7ceb-3fdd-4625-aa82-1d4195f984b1/passing-multivalue-parameter-in-stored-procedure-ssrs
-- Modification History:
--===========================================================
CREATE FUNCTION [dbo].[SplitListToTable]
(
@List NVARCHAR(2000) ,
@SplitOn NVARCHAR(5)
)
RETURNS @RtnValue TABLE
(
Id INT IDENTITY(1, 1) ,
Value NVARCHAR(100)
)
AS
BEGIN
WHILE ( CHARINDEX(@SplitOn, @List) > 0 )
BEGIN
INSERT INTO @RtnValue
( Value
)
SELECT Value = LTRIM(RTRIM(SUBSTRING(@List, 1, CHARINDEX(@SplitOn, @List) - 1)));
SET @List = SUBSTRING(@List, CHARINDEX(@SplitOn, @List) + LEN(@SplitOn), LEN(@List));
END;
INSERT INTO @RtnValue
( Value )
SELECT Value = LTRIM(RTRIM(@List));
RETURN;
END;
GO
Then you can parse your parameter like this:
SELECT *
FROM YourDatabase.dbo.YourTable
WHERE YourColumn IN(SELECT value FROM dbo.SplitListToTable(@YourParameter, ','))