IN Operator Parameter using stored procedure
Hi Guys,
I'm running a reporting services report using stored procedure and I'm facing a dilemma with the IN Operator in the stored procedure.
Can someone please help me out debugging the statement below? (run it on AdventureWorks Database)
Can I have the @Title Parameter based on another select statement something like this
Set @Title = SELECT Title FROM TableTitle
DECLARE @Title varchar(1000)
set @Title = 'Design Engineer', 'Tool Designer', 'Marketing Assistant'
SELECT FirstName, LastName, e.Title
FROM HumanResources.Employee AS e
JOIN Person.Contact AS c
ON e.ContactID = c.ContactID
WHERE e.Title IN (@Title)
Appreciate all the help on this.
Thank you
John
Hi John,
For your problem, we can use dynamical statement to solve the issue.
Here are 2 options to be clarified:
1. A multi-value parameter will return an array value.
2. It is not able to pass an array in a stored procedure.
To solve the issue, we can use the following steps:
1. Cconvert the array into string that delimited by “,” using the function “Join” in SQL Server Reporting Services.
2. Pass the string in the stored procedure.
3. Combine the parameter and the statement into one simply string.
4. Execute the simply string.
Here are the detailed steps for your reference:
1. In Report Designer, create a new dataset as “SELECT Title FROM TableTitle”.
2. Create a new multi-value parameter, set the available value from the dataset above.
3. Set the query of the main dataset as :
="spSelect_Title "&Join(Parameters!para.Value, ",")
4. Change the stored procedure as:
ALTER PROCEDURE [dbo].[spSelect_Title]
-- Add the parameters for the stored procedure here
--@Query NVarchar(Max),
@Title NVarchar(MAX)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @Query Varchar(Max)
SET @Query = 'SELECT FirstName, LastName, e.Title
FROM HumanResources.Employee AS e
JOIN Person.Contact AS c
ON e.ContactID = c.ContactID
WHERE e.Title IN (' + @Title+ ')'
-- PRINT ' QUERY = '+ ISNULL(@Query,'NULL')
Execute sp_executesql @Query
END
If you have any more questions, please feel free to ask.
Thanks,
Jin
Jin Chen - MSFT
Similar Messages
-
LOV parameter using stored procedure.
I have a report has one parameter and uses stored procedure to retrieve the content. The parameter (drop down box) is a dynamic list-of-value with another stored procedure to retrieve the data. Without using any business view object.
I deployed the report into the server. I have set the database properties in the Process->Database option. When I preview the report, it always prompts me to enter the user name and password for database connection before the parameter page.
How and where to set the connection user name and password for the dynamic list-of-value stored procedure data source?
Thanks.Try the following:
- Go to the Repository Explorer in Business View Manager.
- Right-click the LOV. Click Schedule.
- Click the Parameters tab. Enter the correct parameters. If Database Logon is available, provide the correct database logon information.
- Schedule the LOV to a recurring schedule that fits the business needs (for example, daily, hourly, or weekly).
The LOV will not run on demand, but the report can be run on demand.
Caroline -
Why Dynamic Parameter is not working, when i create report using stored procedure ?
Post Author: Shashi Kant
CA Forum: General
Hi all
Why Dynamic Parameter is not working, when i create report XI using stored procedure ?
Only i shaw those parameters which i used in my stored procedure, the parameter which i create dynamic using stored procedure
is not shown to me when i referesh the report for viewing the results.
I have used the same procedure which i mention below but can not seen the last screen which is shown in this .
============================================================================================
1. Select View > Field Explorer2. Right-click on Parameter Fields and select New from the right-click menu.3. Enter u201CCustomer Nameu201D as the name for your parameter4. Under u201CList of Valuesu201D select u201CDynamicu201D5. Under the Value column, click where is says u201Cclick here to add itemu201D and select Customer Name from the drop-down list. The dialog shown now look like the one shown below in Figure 1. Click OK to return to your report design.
Dynamic Parameter Setup6. Next, select Report > Select Expert, select the Customer Name field and click OK.7. Using the drop-down list beside select u201CIs Equal Tou201D and using the drop-down list, select your parameter field (it should be the first field). 8. Click OK to return to your report design and see the parameter dialog.The parameter dialog will appear and show you a dynamic list of values that is updated each time your run your report. It couldnu2019t be easier! In our next tutorial, we will be looking at how to use this feature to create cascading parameter fields, where the values are filtered by the preceding selection.
Dynamic Parameters in Action
My question is that whether dynamic parameter is working with storedprocedure or not.
When i added one table and try to fetch records using dyanmic prameters. after that i am not be able to find the dynamic parameter option when i referesh my report.
One more thing when i try the static parameter for my report, the option i see when i referesh the screen.
Please reply soon , it's urgent
Regards
shashi kantHi Kishore,
I have tested the issue step by step by following you description, while the first issue works well in my local environment. Based on my research, this can be caused by the lookup expression or it indeed return Male value based on the logic. If you use the
expression below, it will indeed only return the Male record. So please try to double-check the record in the two datasets and the expression in your environment:
=lookup(first(Fields!ProgramID.Value,"DataSet1"),Fields!ProgramID.Value,Fields!Gender.Value,"DataSet2")
As to the second issue, please try to use the following expression:
=Count(Lookup(fields!ProgramID.value,fields!ProgramID.value,fields!Gender.value,"DataSet2"))
Besides, if this issue still exist, in order to trouble shoot this issue more efficiently, could you please post both the .rdl file with all the size properties to us by the following E-mail address? It is benefit for us to do further analysis.
E-mail: [email protected]
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
How to use dynamic parameter when a report is created using Stored Procedures
Hi all,
any one have the idea of how to use dynamic parameter in crystal report XI R2
when report is created using Stored Procedure.
Regards
shashi kant chauhanHi
You can create an SQL command in Database Expert > Expand your datasource > Add command
Then enter the SQL query that will create the list of values to supply to the user
eg select field1,field2 from table
Then edit the parameter of the report. These will be the SP parameters adn can be seen in field explorer.
Change the parameter type to Dynamic
Under the word Value click on Click here to add item
Scroll down to your Command and select one of the values that you want to appear in the list
e.g field1
Then click on the Parameters field - this is essential to create the param
You can edit other options as required
That should do it for you.
I must say that i use CR 2008 connected to Oracle 10g SP, but i reckon this will work for SQL DB and CR XI as well
Best of luck -
Pass a date parameter to Stored Procedure
Hello friends,
Can you help to pass a date parameter to Stored procedure from JSP. This is my code:
In Oracle 9i I have this:
PROCEDURE SP_EDORES(
pfechaini IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
pfechafin IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
p_recordset OUT PKG_REP_CIERRE.cursor_type) AS
In JSP have this:
CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
stmt.setDate(1,Date.valueOf("01-06-2005"));
stmt.setDate(2,Date.valueOf("30-06-2005"));
ResultSet rset = (ResultSet)stmt.getObject(3);
while (rset.next()) {
%>
<TR>
<TD ALIGN=CENTER> <%= rset.getString(1) %> </TD>
<TD ALIGN=CENTER> <%= rset.getString(2) %> </TD>
<TD ALIGN=CENTER> <%= rset.getString(3) %> </TD>
<TD ALIGN=CENTER> <%= rset.getInt(4) %> </TD>
</TR>
<%
The Stored Procedure returns de Result set, however I think does not recognized the date format because I need it with this format dd-mm-yyyy.
Thanks in advanceto use Date you will need the oracle package.
u can try this other solution: use String, not Date
CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
stmt.setString(1,"01-06-2005");
stmt.setString(2,"30-06-2005");
ResultSet rset = (ResultSet)stmt.getObject(3);
while (rset.next()) {
%>
if this don't work you can change your PL/SQL to get Strings and do the conversion with TO_DATE in the sql statement. -
Using Stored Procedure Universe in Reports
Hi Friends,
I got some issues using SP's in Universe and WebI Report.
Case #1:
Can we execute dynamic SQL using stored procedure universe..?
I use SQL server as the DB for my reports.I created a SP which will execute on getting a input value from the user.This input value will frame the SQL dynamically in the SP.for executing the dynamic SQL i use sp_executesql inside the SP.The SP wexecutes successfuly in the DB but when i try executing it in the Universe i get a error message as follows: "Exception : DBD,[Microsoft][SQL SErver Native Client 10.0][SQL Server]Incorrect syntax nesr 'FROM'.State:42000"
The script i used for creating SP for your reference:
CREATE PROCEDURE P_S_GetCodeValueList
@s_table nvarchar(75)
as
begin
declare @s_sqlCommand nvarchar(1000)
declare @s_tablename nvarchar(75)
declare @s_code nvarchar(75)
set @s_tablename=@s_table
set @s_code = '*'
set @s_sqlCommand= 'SELECT ' + @s_code + ' FROM ' + @s_tablename
exec sp_executesql @s_sqlCommand
end
Case #2:
AIl also tried creating reports using the SP Universe which needs to get the parameter when the user refesh the report.
But every time the report is refreshed the report fetches the data which was produced when the SP is executed in the Universe for the first time.
I need to get the prompt in the report , to which the user could give a value and the SP gets executed for that value.
Is there any option in BO to do this?
It will be very helpful if you could give me some work arounds on this.
Regards,
SugumarHi Sugumar,
I can answer you for your 2nd question:
When you create the Stored procedure in the Universe and test it on retreiving data by inserting variable input you can check if the user could insert new value for the SP parameters.
Hope this helps!
Regards
Giuseppe -
Passing parameter in stored procedure
Hi, I am really new to using Oracle stored procedure. I have just tested a sample stored proc which should return multiple rows without passing any parameter.
here is the stored proc I wrote
create or replace procedure get_address
as
cur_table sys_refcursor;
begin
open cur_table for
select * from address_table order by addr_id;
end;
when I execute it, I get a message "Procedure Created"
then I executed the stored proc
exec get_address;
I again get a message "PL/SQL procedure successfully completed" and I do not see the records at all.
so I decide to rewrite to the stored proc as such
create or replace procedure get_address(cur_table out sys_refcursor)
as
begin
open cur_table for
select * from address_table order by addr_id;
end;
everthing is good so far.
now when execute it
exec get_address;
I am getting the following error:
"PLS-00306: wrong number or types of arguments in call to 'TESTCODEPROC'"
I have searched so many places, but there is no document talks about this issue. I hope someone can help me to over come this. I need to call this stored proc from .NET 2.0 reporting viewer which is embedded in asp.net page.
Thank you.so I decide to rewrite to the stored proc as such
create or replace procedure get_address(cur_table out
sys_refcursor)
as
begin
open cur_table for
select * from address_table order by addr_id;
end;
everthing is good so far.
now when execute it
exec get_address;
I am getting the following error:
"PLS-00306: wrong number or types of arguments in
call to 'TESTCODEPROC'"
From what you wrote I can assume that you have used SQL server before. Oracle does not automatically return the last opened cursor from a stored procedure like the query result, so you cannot just call exec get_address; (or just execute the procedure from .NET code). You will have to pass the cursor parameter and fetch it as an output parameter value in .NET, then use it to get the data reader etc.
On the other hand, you can just execute the statement directly. I see a lot of folks coming from SQL server world using stored procedures like crazy even for things that are naturally suited to queries and views. Oracle view allows you to apply the same security restrictions you can put onto a stored procedure, and if you use statement caching and bound variables, you get precompilation benefits as well with a view. Using a view instead of a procedure in this case will require less code both in the database and in .NET, and will give you a more flexible interface in terms of retrieved columns and ordering.
gojko adzic
http://gojko.net -
Best approach for performing DMLs using stored procedures
Hi,
I have a really general question and would like to hear your say about this.
I want my application to manipulate or read data using stored procedures (or packages in that manner) and not directly using queries against the DB.
Let's say I have a table with many columns:
create table test (pkid number(10),col1 varchar2(30), col2 number(10), col3 date,...);For such a DML procedure, is it best to do something like
procedure do_update(i_pkid IN number,i_col1 IN varchar2, i_col2 IN number, i_col3 IN date,...) as
begin
update test
set col1=i_col1,
col2=i_col2,
col3=i_col3...
where pkid=i_pkid;
commit;
end;Or do a selective update, meaning update only a certain column every time, given only 1 column actually changes? (and how to do that - separate procedures for each column? [columns can be nulls])
Also, is it better to work with test.col1%type instead of specifying the data type in the procedure?
And one last question - If I have a table with 100 columns and I don't want to create a procedure with 100 parameters - the best approach would be to use a record?
I just need to be set on the way I start implementing things in order to do it well from the start.
Many thanks.
Edited by: Pyrocks on Nov 17, 2010 1:58 PMPyrocks wrote:
One last clarification (although it may be more related to c/c++ developers - maybe one of you will know):
We are working with C++ and VB against a SQLServer and my part is to translate all the existing procedures to Oracle in order to migrate the application to work with Oracle DB.
The existing procedures use an IN parameter for each column in the table and I would really like to use rowtype like you mentioned.
Since I'm not a c/c++/vb developer - is there an easy way of working with such types, or even User-Defined Types, from c/c++/vb (as in passing a rowtype record from c++ to a SP ?)
I'm not looking for the actual way - just want to know how hard it would be and how much code needs to be changed in order to be able to convince the developers that this is the RIGHT way to work.
PS. none of our developers have experience with ORACLE so they wouldn't know the answer...Not actually an Oracle server-side (SQL language or PL/SQL language) question - but a client one. And it has been a long time since I wrote a fat client using C/C++ or Delphi.
The OCI (<i>Oracle Call Interface</i>) supports advance (user defined) SQL data types. Has since Oracle 8i. So in that respect, yes the client can support custom SQL data types.
How well it does depends entirely on that client language's features wrt OCI integration. For example, Delphi 4 was release around Oracle 8i and supported custom SQL types. I would expect that most languages today (like Java and C#) will provide support for it.
As for usiong +%ROWTYPE+ - this is a PL/SQL clause as far as I know. Unsure whether it is supported by the OCI. What could support it is a pre-compiler like Pro*C. These enable you to mix pseudo SQL source code with client language source code. The pre-compilation step then replaces the pseudo SQL code with native client language calls to the OCI. The code is then compiled by that client language's compiler. Pre-compilers can pull all kinds of interesting "tricks" with their pseudo SQL code support.
The best would be to consult the applicable client language's manuals that describe the interface it supports (via OCI) to Oracle. -
Is it possible to pass TABLE as the output parameter in stored procedure
Hey Experts,
Is it possible to pass TABLE as the output parameter in stored procedure.
eg
create procedure spGetData
@tableName as TABLE(intValue INT NOT NUL)
asYou can use OPENQUERY or OPENROWSET, as mentioned above, to make stored procedure results table like. There are
some limitations with these methods:
http://technet.microsoft.com/en-us/library/ms188427.aspx
In OPENQUERY this-sql-server-instance can be used instead of a linked server name. It requires setting data accces server option:
exec sp_serveroption @server = 'PRODSVR\SQL2012'
,@optname = 'DATA ACCESS'
,@optvalue = 'TRUE'
LINK: http://www.sqlusa.com/bestpractices/select-into/
Kalman Toth Database & OLAP Architect
SELECT Video Tutorials 4 Hours
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Using stored procedures for insert, update and delete
Hello all;
We have a question from our customer (who is the DBA), who has not in the past used TopLink, about whether it makes sense to tie TopLink into existing stored procedures to save and retrieve informations.
Is it possible?
Is there any circumstance under which it is a good idea?
ThanksIn TopLink any operation for which TopLink generates SQL, can be replaced by custom SQL, or a stored procedure call.
Custom SQL or stored procedures can be used for each of the descriptor's CRUD operations, but also for mapping queries and named queries. The Mapping Workbench only supports defining custom SQL for the descriptor CRUD operations and named queries, so many of the stored procedures call from the descriptor and mappings will need to be done through amendment methods.
Whether it makes sense or not depends on the application and the company and their requirements. It will add significant overhead to the development process to have to define and maintain all of the stored procedures, and the stored procedure calls in the descriptors. You may wish develop your application using TopLink generated SQL, and once you have the model and queries stabilized then switch to using stored procedures.
Whether it is a good idea depends on the application and the company and their requirements. Stored procedures may give the DBA more freedom to change the data-model once in production, and may allow for adding database-level security checks. In general using stored procedures will not improve performance if the procedures contain the same SQL that would have be executed anyway, but they may allow for the DBA to tune the SQL better. -
REF CURSOR as IN parameter to stored procedure
Currently, ODP.NET supports REF CURSOR parameter as OUT parameter only.
Based on the project requirements it is necessary to pass
multiple records to the stored procedure.
In this case REF CURSOR as IN parameter is useful.
What are the plans to implement REF CURSOR as IN parameter to stored procedure?
What is the work around in case it is necessary to pass several different
record types as arrays to stored procedure?ODP.NET does not limit REF Cursor parameters to IN parameters. This is a known PL/SQL limitation.
An excerpt from Application Developer's Guide:
"If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the server side unless you also open it there on the same server call". -
Sub report using Stored Procedure returns incorrect data
Post Author: rikleo2001
CA Forum: Data Connectivity and SQL
Guys,
I am using CR 9 in ASP.net application.
One simple report and one Sub report, sub report is basically linked with Stored procedure accepting one parameter and returns a select query.
Main report is linked with that sub report using that parameter field.
Sub report is on demand sub report.
Now when I execute that main report and click on on demand sub report I am getting Wrong order information.
Here is out put on main report
Order 1 on demandDetail
Order 2 on demandDetail
Order 3 on demandDetail
NOW If I click on Order 3 (On demanddetail link, it displays rondom order details, some time correct on too), I am really stuck and don't know where I am going wrong.
Please help me to solve this issues.
Many ThanksPost Author: rikleo2001
CA Forum: Data Connectivity and SQL
Hi Yangster,
Thank you so much for your reply.
On DEMAND Sub report is located in main report, IN DETAIL SECTION
I am passing Order ID from main report linked to {?morderid} in subreport under command object, and if I run it in design mode, it works perfectly alright, so problem is isolated to ASP.NET and Crystal report post back method on Crystal report.
The example I give to you this is a simple example to identify issues in my real application and report.
My main report contains summary of data base on unique identifier. that summary have 4 differant types of details which has to be on the same report (as Crystal report doesn't provide Nested subreport), so I decided to use 4 subreports on main report and all subreport using Stored procedure command object.(Sub report has it own complex processing requirement to fulfill).
Please help me with any further ideas? for the sample which I presented to you this is only using one SP on main report with a simple processing.
Many Thanks -
How to build a report in webi XIr2 using stored procedure
Post Author: vijay123
CA Forum: WebIntelligence Reporting
hi,
Is anybody can help me out how to creat a report using stored procedure in webiXir2
thanks
vijayPost Author: amr_foci
CA Forum: WebIntelligence Reporting
this has been posted twice.. i think -
Error while refreshing bqy file on workspace using stored procedure
Hi,
I am using stored procedure which returns ref-cursor. The report is running fine locally but on Workspace, while refresh, it gives the following error.
An Interactive Reporting Service error has occurred.-SQL API: [SQLNumResultCols], SQL RETURN: [-1], SQL STATE: [HY010], SQL NATIVE ERROR: [0], SQL MESSAGE: [[Microsoft][ODBC Driver Manager] Function sequence error]
(0)
I have ODBC/ODBC connection set up at BI+ configurator.
Thanks,
ManishWe also met this issue. Some guy told me this is a Hyperion limitation, is it true? I really need this function in Hyperion:(
-
How to use stored procedure in crystal report for eclipse
Hi;
I am working on crystal report for eclipse 2.0 and trying to use stored procedure in report .It is created from Oracle but it is not showing any dependencies
CREATE OR REPLACE procedure ACT_DB.getCostTransferDetails
p_In_Contract_ID varchar2 DEFAULT '*',
p_In_Status_ID varchar2 DEFAULT '*',
p_In_COST_TRAN_DATE varchar2 DEFAULT '*',
p_In_DEPT_ID varchar2 DEFAULT '*',
p_In_PROJECT_ID varchar2 DEFAULT '*',
p_In_EMPLOYEE_ID varchar2 DEFAULT '*',
p_Out_CostTransfer_Cusor OUT COST_TRANSFER_PACKAGE.COST_TRANSFER_TYPE
AS
BEGIN
OPEN p_Out_CostTransfer_Cusor FOR
SELECT
header.cost_tran_id,
header.cost_tran_date,
header.total_credit_amount,
header.total_debit_amount,
header.transfer_status,
header.updated_by,
header.added_by,
header.trf_over_ninety_days,
header.business_unit_id,
header.equip_approval,
header.batch_desc,
details.opr_unit_id,
status.status_id,
details.fund_code_id,
details.prgm_code_id,
details.class_id,
details.activity_id,
details.product_id,
details.status_id,
details.transaction_amount,
details.jrnl_date,
details.adjust_prcnt,
details.adjust_amnt,
details.details_equip_approval,
details.detail_desc,
details.account_id,
details.project_id,
details.dept_id,
details.contract_id,
details.reason_code_id,
details.jrnl_id,
employee.f_name,
employee.l_name,
employee.employee_id,
project.project_id,
project.project_status,
--header.transfer_status,
contracts.contract_desc
FROM header, details, status, employee, department, project, contracts
WHERE (header.cost_tran_id = details.cost_tran_id)
AND (header.cost_tran_date = details.cost_tran_date)
AND (header.transfer_status = status.status_id)
AND (department.dept_id = details.dept_id)
AND (department.dept_id = employee.dept_id)
AND (project.project_id = details.project_id)
AND (contracts.contract_id = details.contract_id)
AND (details.Contract_ID = p_In_Contract_ID OR p_In_Contract_ID ='*' )
AND (header.TRANSFER_STATUS = p_In_Status_ID OR p_In_Status_ID ='*' )
AND (TO_CHAR(details.COST_TRAN_DATE, 'MM/DD/YYYY') = p_In_COST_TRAN_DATE OR p_In_COST_TRAN_DATE ='*' )
AND (details.DEPT_ID = p_In_DEPT_ID OR p_In_DEPT_ID ='*' )
AND (details.PROJECT_ID = p_In_PROJECT_ID OR p_In_PROJECT_ID ='*' )
AND (header.ADDED_BY = p_In_EMPLOYEE_ID OR '*'=p_In_EMPLOYEE_ID )
Can any another way to make procedure
Thanx
Regards ,
AmolHi Amol,
Are you able to execute your stored procedure from oracle?.
- If "Yes" then use the Crystal Report XIR2 Designer to create the report.
- Import this report in the Crystal Report For Eclipse Workbench.
- The latest version for Crystal Report For Eclipse is SP1.
Please let me know the results.
Thanks,
Neeraj
Maybe you are looking for
-
Is it possible to connect Apple TV to Marantz SR8001 via HDMI?
Video won't display, says there's no source. I updated my Apple TV software to the latest version, this setup was never tested through the previous version. I'm using Apple's HDMI cable so that's not an issue. The device connects directly to my TV's
-
INSTALL HP LASERJET 2820 ON WINDOWS 7...
Good evening. Could greatly use some help. Installed Windows 7 and am now trying to figure out how to get my HP Color Laserjet 2820 (all-in-one) functioning. Which software installation do I download from HP? How do I "fool" the system or use the com
-
Could I take 1Z0-051 and 1Z0-047 together?
Hi, I am currently planning to take a Oracle PL/SQL Developer Certified Associate. At first, I plan to take the path of 1Z0-047 + 1Z0-144 which leads to this certification, because the 1Z0-047 itself is also leading to another cert (Oracle SQL Expert
-
Address Book Images Gone Funky
Adding images to Address Book contacts just results in a random part of the image showing. In iOS I can add images just fine, and they show up in Address Book ok. It's never done this before. Any ideas??
-
Migration of _Communities Section in Content Server
Hi, I want to migrate some Content portlets. With the Migration Wizard, I can't choose the section "_Communities" and my sections are in this folder. Can I migrate the "_Communities Section" ?