SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Passing Multivalue Parameter


Passing Multivalue Parameter

Author
Message
peer_mohamed2k
peer_mohamed2k
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 59
How to pass Multivalue parameter in Reporting Services.

In my Report DataSet, I am using statement like this.
Exec SalesReport @SalesTerritory, @ProductName, @StartDate,
@EndDate

Here @SalesTerritoy and @ProductName are Multivalue parameters. And I am Selecting more than one value for the paramenters from the drop down.

In sql Procedure I am splitting the comma separated values and putting to temp table.

Thnx in Advance.
Elmer Miller
Elmer Miller
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1023 Visits: 250
I'm not sure I understand your question, but it sounds like you need help with the sql procedure to make use of the multi-value parameter.
I usually do this by making the multi-value parameter a varchar(max) then in the query use the IN operator to filter the results like this:

select ...
from Sales
where ProductKey in (select convert(value,int) from dbo.Split(@ProductKeyList,',',default,default))

The Split function I use is:
--This UDF will split a delimited list into a table.
ALTER FUNCTION [dbo].[Split]
(
@list NVARCHAR(4000)
, @delimiter NVARCHAR(10) = N','
, @include_null BIT = 0
, @null_text NVARCHAR(10) = NULL
)
RETURNS @tableList TABLE(
idx SMALLINT IDENTITY (1,1) PRIMARY KEY,
value NVARCHAR(100) NULL
)
AS
BEGIN
DECLARE @value NVARCHAR(100)
DECLARE @position INT

SET @list = LTRIM(RTRIM(@list))+ @delimiter
SET @position = CHARINDEX(@delimiter, @list, 1)

IF REPLACE(@list, @delimiter, '') <> ''
BEGIN
WHILE @position > 0
BEGIN
SET @value = LTRIM(RTRIM(LEFT(@list, @position - 1)))
IF @include_null = 1 OR @value <> ''
BEGIN
IF @value = '' SET @value = @null_text
INSERT INTO @tableList (value)
VALUES (@value)
END
SET @list = RIGHT(@list, LEN(@list) + 1 - LEN(@delimiter) - @position)
SET @position = CHARINDEX(@delimiter, @list, 1)
END
END
RETURN
END
swiering
swiering
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 2
Worked perfect for me, Elmer, Thank You!! Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search