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


T-SQL query to add multiple valued report parameter


T-SQL query to add multiple valued report parameter

Author
Message
charanadevi
charanadevi
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 22
SELECT
Persons.P_id
,Persons.LastName
,Persons.FirstName
,Persons.Address
,Persons.City
FROM
Persons
where Persons.P_id IN (@P_id)

the above query consider only one parameter when I try to pass two parameters say '1,2' error: conversion failed. how can i pass multiple values by adding simple T-SQL query as,I am directly working on dataset I can not work with ssrs reports and allow multiple values or stored procedure. Is their any other way Just to write any simple t-sql query to solve this. Any help would be appreciated.
subbu1
subbu1
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1293 Visits: 695
first create function after call that function in your query...

Text


CREATE FUNCTION SPLIT(@VAL VARCHAR(MAX))
RETURNS @T1 TABLE(COL1 VARCHAR(MAX))
AS
BEGIN
WHILE CHARINDEX(',',@VAL)>0
BEGIN
INSERT INTO @T1 VALUES(SUBSTRING(@VAL,1,(CHARINDEX(',',@VAL))-1))
SET @VAL=SUBSTRING(@VAL,(CHARINDEX(',',@VAL))+1,LEN(@VAL))
END
INSERT INTO @T1 VALUES(@VAL)
RETURN
END

SELECT
Persons.P_id
,Persons.LastName
,Persons.FirstName
,Persons.Address
,Persons.City
FROM
Persons
where Persons.P_id IN (select * FROM split(@P_id))
charanadevi
charanadevi
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 22
Thank you so much. Thant worked for my code
charanadevi
charanadevi
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 22
Hi,
This code works good when my souce is SQL. Now when my datasource is not SQL and it is Oracle then it is not working. how should I implement this code to work when choose Oracle datasource for shared dataset query designer.
Any suggestions.
Thanks
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)

Group: General Forum Members
Points: 32787 Visits: 16637
Your original requirement was a T-SQL query which, if I understand correctly, isn't going to work against an Oracle database. You'll need to go to an Oracle forum to get help on that. There may be a way of writing code that works on both Oracle and SQL Server.

John
yudy.varma
yudy.varma
SSC-Enthusiastic
SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)

Group: General Forum Members
Points: 115 Visits: 160
i executed the the below function

CREATE FUNCTION SPLIT(@VAL VARCHAR(MAX))
RETURNS @T1 TABLE(COL1 VARCHAR(MAX))
AS
BEGIN
WHILE CHARINDEX(',',@VAL)>0
BEGIN
INSERT INTO @T1 VALUES(SUBSTRING(@VAL,1,(CHARINDEX(',',@VAL))-1))
SET @VAL=SUBSTRING(@VAL,(CHARINDEX(',',@VAL))+1,LEN(@VAL))
END
INSERT INTO @T1 VALUES(@VAL)
RETURN
END

Below mentioned is my SP

--exec Fms_Subject 'M001,L001,D004,B001'

Alter Proc Fms_Subject

@Subject_No Varchar(25)

As
Begin
Set NoCount ON

select Subj_SCode,Subj_SName from ERP_Subj

WHERE (Subj_SCode IN (select Subj_SCode from split(@Subject_No)))

order by Subj_SCode

End

when i executed this SP its showing all the records,it is supposed to show the records pertained to passed values i.e: 'M001,L001,D004,B001'
can you tell me how to get the data pertained to only specified values.
Attachments
SP.JPG (9 views, 149.00 KB)
ScottPletcher
ScottPletcher
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18576 Visits: 7401
SSRS will automatically properly expand an "IN (@multi_valued_report_parameter)" if it's in an SSRS dataset and follows some basic rules. You may want to verify that you have a proper SSRS dataset.

SQL DBA,SQL Server MVP(07, 08, 09) Prosecutor James Blackburn, in closing argument in the Fatal Vision murders trial:
If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them.
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