Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

T-SQL query to add multiple valued report parameter Expand / Collapse
Author
Message
Posted Wednesday, October 17, 2012 9:50 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, January 14, 2014 3:11 PM
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.
Post #1374127
Posted Wednesday, October 17, 2012 10:12 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, September 3, 2014 9:44 PM
Points: 888, Visits: 671
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))
Post #1374131
Posted Wednesday, October 17, 2012 10:42 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, January 14, 2014 3:11 PM
Points: 5, Visits: 22
Thank you so much. Thant worked for my code
Post #1374135
Posted Friday, October 19, 2012 7:37 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, January 14, 2014 3:11 PM
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
Post #1374819
Posted Friday, October 19, 2012 7:47 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, October 31, 2014 11:06 AM
Points: 5,430, Visits: 10,108
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
Post #1374829
Posted Saturday, December 22, 2012 12:52 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Today @ 5:19 AM
Points: 17, Visits: 154
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.









  Post Attachments 
SP.JPG (2 views, 149.15 KB)
Post #1399660
Posted Monday, December 24, 2012 10:00 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 3:44 PM
Points: 2,266, Visits: 3,419
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)

Carl Sagan said: "There is no such thing as a dumb question." Sagan obviously never watched a congressional hearing!
Post #1399934
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse