Output Parameters in SSRS - reporting-services

How do I create a report with a Stored Procedure which has an output parameter?
The report can be developed but returning the output parameter is what I am trying to figure out.

SSRS does not support output parameters by default.
If your SP does not return any resultset, you can get the output parameters by wrapping the SP call in a regular query text:
DECLARE #x
EXEC dbo.YourSP #outX = #x OUTPUT
SELECT #x

Related

How to Get Tables Data in out parameters of Store Procedures in mysql

I was trying to get data into the Output parameters of Stored Procedure in mysql but I am not getting it back.
HERE IS THE QUERY
Creation
CREATE DEFINER=`root`#`localhost` PROCEDURE `get_initial_data`(
out usersData varchar(500),
out employeesData varchar(500)
)
BEGIN
SELECT * into usersData FROM users;
SELECT * into employeesData FROM employees;
END
Calling
Call get_initial_data(#users, #employees)
select #users
select #employees
I tried this and I am able to create the Store Procedure but not able to call, its giving me this Error...
Error Code: 1172. Result consisted of more than one row
Can you help me in this, am I passing the Output parameters correctly and also the Data type of that?
Please let me know your response on this....
An output parameter can contain only a single value. You are trying to return result sets via the output variable. This is not how output parameters work.
You read the result sets coming from the procedure; no need to use output variables.
CREATE PROCEDURE get_initial_data()
BEGIN
SELECT * FROM users;
SELECT * FROM employees;
END
Output parameters are useful in a situation where you have a procedure calling another procedure and use the output of the called procedure. Even then, you can only use single values with output parameters.

Add input parameter to stored procedure and passing it into an output variable?

I currently have a stored procedure I'm working on that's supposed to output a message when something fails.
ALTER PROCEDURE---
#in_id INT
#msg NVARCHAR(30) = OUTPUT
The procedure variables are structured like this where one of them is an input parameter and the msg is an output.
The idea is that it uses that input parameter of an ID which works as an identification that changes the message based on the ID so the end of the sproc looks something like:
SET #msg = usf_change_message(#id, #msg)
I get an error stating that the sproc is trying to treat #msg as an input variable when in actuality it's an OUTPUT param? Can someone help me with this issue?
You use your SP as function which is obviously wrong - SP does not return a value.
You must use:
CALL usf_change_message(#id, #msg);
SELECT #msg;
Or you may convert SP to UDF and use your SELECT query (but in this case #msg in UDF parameters is excess and should be removed).

Loop through stored procedures with input and output parameters

I am looking for a script for look through stored procedures with input and output parameters.
I use the following script to manually input processdate and get the date id as output. Every time I just change the #ProcessDate to process.
Does anyone have a better way to write a loop to run this stored procedure and set the #ProcessDate from 2017-04-30 to 2017-08-31?
Appreciate it!!
Declare
#ProcessDate datetime,
#Date_ID int
select #ProcessDate = '2017-04-29'
exec casp_Dim_Date #ProcessDate, #Date_ID output

able to select multiple dates (parameter) in ssrs

Is there a way where in I can select multiple dates and pass it as my parameters for a stored proc for a report in ssrs. selecting allow multiple values for a parameter gives a dropdown list. but can i get a calender control where I can select Multiple dates.
SQL Server Reporting Services, as of version 2008R2, does not have this functionality built in. I haven't looked at 2012, but I'd be surprised if it offered this.
(You can always build your own interface using a ReportViewer control, URL access or another access method to display reports.)
As Jamie stated, you can't really do this. The "best" work around I have come across in my experience is to pass your parameter value(s) as one text string, and use a split function to parse in your WHERE condition in the stored proc.
USE [YOUR DATABASE]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[split](
#delimited NVARCHAR(MAX),
#delimiter NVARCHAR(100)
) RETURNS #t TABLE (id INT IDENTITY(1,1), val NVARCHAR(MAX))
AS
BEGIN
DECLARE #xml XML
SET #xml = N'<t>' + REPLACE(#delimited,#delimiter,'</t><t>') + '</t>'
INSERT INTO #t(val)
SELECT r.value('.','varchar(MAX)') as item
FROM #xml.nodes('/t') as records(r)
RETURN
END
Your parameter would be something like this in your stored proc:
#Parameter VARCHAR(200)
Then your where condition in your stored proc will be something like this
where convert(varchar(10), cast([YOURDATE] as date), 101) IN (select val from dbo.split(#Paramater,','))
I hope this helps!

SSIS Execute SQL Task Out Parameter of -1 not showing up right

This is the goofiest thing I've seen all day.
In SSIS 2005, I have an Execute SQL Task which runs a SQL 2005 stored proc that takes two IN parameters and one OUTPUT parameter. The IN parameters are static and so are hard-coded in the command string. The OUTPUT parameter is pulled into a package variable of type Int32 (although in the Execute SQL Task on the Parameter Mapping page it tells me the data type is LONG).
When I run the SQL Task and the output parameter is returning a value > 0 (like 2), the variable is populated with 2. When I run the SQL task and the output parameter is returning -1, the package variable is populated with some value like 66682316. I can run the proc in SSMS and if the value is pre-populated with -1, it returns -1 to me.
DECLARE #out int
SET #out = -1
EXECUTE MyProc 'param1', 'param2', #out OUTPUT
SELECT #out -- returns -1
Does anyone have any idea why it would be returning this value instead of -1? I'm sure my variable is Int32 and not UInt32.
If you set up your sql command like you did, you should be setting your variable from the result set not from the parameters.
Set Result Set to Single Row, then on the result set tab put 0 (if you are using OLEDB) as your result name and your variable (i.e. User::OutputVariable) as your variable name.
If you want to use parameters, you would set your sql up like this:
EXECUTE MyProc 'param1', 'param2', ? OUTPUT
Then you would go to the parameter mapping tab and set up your parameter as follows:
Variable Name -> User::OutputVariable
Direction -> Output
Data Type -> Long
Parameter Name -> 0
Parameter Size -> -1
NOTE This applies to using OLEDB as the connection type on the general tab. How parameters are named is different depending upon connection type used.
Shoudl you be saying
SELECT ? = #Out