Hey,
I'm building a custom report using stored procedure via SSRS 2008, which has a multiple value parameter. This multiple value parameter might have values with single quote, such as: abc, efg's, sms dio, 'you's dfd.
I found most of the solution for passing multiple value to stored procedure is to create a user defined function to put the string to a table, then grab the value from table to stored procedure. At the beginning, I used the same way to do it. This is the function I used:
There is one alternative way to make it work is not using stored procedure, just put the query into the dataset directly instead of using stored procedure and pass this multiple value to query.
My question is: If I still really want to stored procedure, how can I pass this kind of value(with single quote) of parameter to my stored procedure?
Anyone has any idea?
Thanks in advance!
I'm building a custom report using stored procedure via SSRS 2008, which has a multiple value parameter. This multiple value parameter might have values with single quote, such as: abc, efg's, sms dio, 'you's dfd.
I found most of the solution for passing multiple value to stored procedure is to create a user defined function to put the string to a table, then grab the value from table to stored procedure. At the beginning, I used the same way to do it. This is the function I used:
CREATE FUNCTION [dbo].[ufn_String_To_Table] ( @String VARCHAR(max), /* input string */ @Delimeter char(1), /* delimiter */ @TrimSpace bit ) /* kill whitespace? */ RETURNS @Table TABLE ( [Val] VARCHAR(4000) ) AS BEGIN DECLARE @Val VARCHAR(4000) WHILE LEN(@String) > 0 BEGIN SET @Val = LEFT(@String, ISNULL(NULLIF(CHARINDEX(@Delimeter, @String) - 1, -1), LEN(@String))) SET @String = SUBSTRING(@String, ISNULL(NULLIF(CHARINDEX(@Delimeter, @String), 0), LEN(@String)) + 1, LEN(@String)) IF @TrimSpace = 1 Set @Val = LTRIM(RTRIM(@Val)) INSERT INTO @Table ( [Val] ) VALUES ( @Val ) END RETURN END GOIn order to convert the multiple value to a single string(which the @string argument for the function) to be used by this user defined function, I use JOIN function in SSRS report. After I execute my stored procedure, I found all records related to single quote value parameter are missing. There must be something wrong with this function, or the way it passed the parameter. It doesn't work any way, no matter how I tried to replace single quote to two single quote, or replace to blank.
There is one alternative way to make it work is not using stored procedure, just put the query into the dataset directly instead of using stored procedure and pass this multiple value to query.
My question is: If I still really want to stored procedure, how can I pass this kind of value(with single quote) of parameter to my stored procedure?
Anyone has any idea?
Thanks in advance!