How to Store an Aggregated Value in a Stored Procedure? - stored-procedures

I am using SQL Server 2012 and trying to write a stored procedure that will have two components:
1. Select statement that will return several rows
2. Another component will have an aggregated value based on some conditions.
So, for the second component, I am thinking to declare a variable in the stored procedure and store the aggregated data there.
Now, my question is can I populate my output parameter with the data stored in previously declared variable and access the parameter from SSRS 2012?
I would appreciate any suggestion(s) to get me started.
Thank you

Related

Table valued Parameters equivalent in db2

I am trying to pass a collection of Employee objects from Java code to a DB2 Stored Procedure. In SQL server I can do that by making use of Table-Valued Parameters. In DB2 how can I achieve this?
Refer to Invoking stored procedures with ARRAY of ROW parameters in JDBC applications.
Or use Declared Global Temporary Table creating it and inserting rows into it beforehand and use this DGTT in your SP as ordinary table.

Can I have table variable in stored procedure in redshift?

We are planning to create a procedure for our logic what should be in PL SQL in redshift (using workbench).
Can we use a table variable to traverse through the rows of the table ? Like we have dataframe in Python.
Sort of. Redshift implements a RECORD data type for stored procedures. Variables with this type can hold an arbitrary sets of rows.
"Overview of stored procedures in Amazon Redshift" > "Record types"
However, note that you cannot currently SELECT from a RECORD typed variable, only loop over the content.
There are several examples of using a RECORD variable in our GitHub repository: "amazon-redshift-utils/src/StoredProcedures/"

Insert array of JSON objects in db2 stored procedure

I'm trying to pass an array of JSON objects to the Stored procedure, so that each JSON object will be stored in a single row of the table.
for an example:
to insert a single entry: INSERT INTO SCHEMA_NAME.TABLE_NAME (id,name) values (1,'my_name')
now i have an array of such data which I want to push into stored procedure to get all data inserted into table without hitting SP again and again.
array example: [{id:1,name:'name1'},{id:2,name:'name2'}]
now i can have number of object to be stored.
so either i would hit the SP again and again to push each object individually or i would pass whole array and run a loop inside a stored procedure to get it done.
I have DB2 10.5 LUW with fixpack 7 installed and using node.js
DB2 10.5 does not support JSON as a native data type, so you won't be able to do this without passing the JSON as a VARCHAR and having the stored procedure parse/deconstruct the JSON. The obvious way to do this would with a C or Java stored procedure.
That said, there are some JSON capabilities (see this series of articles for more details, but this is almost certainly not what you want.

What order are result sets returned when using JDBC callable stmt to stored proc?

(1) When you open multiple cursors in a stored procedure, and then use a JDBC callable statement to iterate through the result sets, each in turn, are the order in which they are returned the same order in which they cursors are opened in the stored procedure? Or reverse of that? Or....?
(2) Is there a way to specify by sequence number or name which result set to process first?
For 1: The order of returned resultsets is undefined for JDBC, so it will depend on your actual database system. That said, it would be highly illogical for a stored procedure to return results in a different order than the order they are produced by the stored procedure.
For 2: Once again, this is not defined by JDBC. However I haven't heard of database systems that would allow you to control the order of returned results by any means other than their order in the stored procedure.

SSRS: Passing different parameter values to stored procedure for two Data Sets

I have two tables in my Report. Both use two separate Data Sets, which get data from the same Stored Procedure. Now, I want the data sets to get different data based on different parameter values. Is there a way to achieve that? I am using SQL Server 2008-R2. Thanks in advance...
Within the Report Data screen (Ctrl+Alt+D), you can tie both datasets up to different parameters.
Add your parameters
Open up the Datasets properties
Go to the parameters section
Add the required parameter and give it a name the same as your Stored Proc parameter e.g. #EmployeeId
providing the query is marked as type "Stored Procedure" (in query section), this will pass the parameter over on selection. Repeat the process for the other dataset

Resources