How to get procedure result in another procedure without OUT parameter - mysql

I have made a procedure which returns multiple values and i want to use these values in another procedures without OUT parameter. is there any solution?

Depending on the actual type of result you want to "transfer" from one procedure to the next there are different options:
If your fist procedure produces only a small number of individual values (like a single id or a count or sum of something) you can store them in (a) variable(s) and use them for calling the next procedure. Otherwise - for data in a tabular form - you can create a temporary table which you then access from your second procedure.

Related

Mutually dependent parameters

Is it possible to change ONE parameter drop down values if ANOTHER parameter drop down values has been changed?
For example, you have two parameters:
drop down YEAR (simply populated int values from stored procedure: 2016,2017,2018)
drop down TYPES (product text value list from stored procedure)
Can we select YEAR 2018 and it will show specific values in TYPES.. then select any other year and show DEFAULT values? Both parameters are calling stored procedures.
IN SHORT:
Idea is to select the year and only show in TYPE parameter related to that YEAR product TYPE.
You can do this but there are a few caveats.
Datepickers don't work well but if you only select a year 9as a number) then this should be fine.
Default selected values may not be set to what you expect if you select a year more than once (i.e. you choose 2018 then change your mind and choose 2017).
Basically you just need to make the seconds dataset, rely on the value of your first parameter. I don't know what you data looks like but let's assume that you have a large dataset and each record has a Year, Type and then some more detailed columns.
Assume you want to choose the year, then choose from s list of types that are present in that year. I won't cover the final dataset as it's not part of your question ..
So let's say the first stored proc does something like
CREATE PROC GetYears AS
SELECT DISTINCT [year] FROM myTable ORDER BY [Year]`
Create a dataset called dsYears and point it to this stored proc.
In SSRS you create a parameter called say #pYear and set the available values to point to dsYears
Now create your second stored proc that accepts a year as a parameter so the proc will look something like
CREATE PROC GetTypes(#pYear as int) AS
SELECT DISTINCT [Type] FROM myTable WHERE [Year] = #pYear
Create a seconds dataset called dsTypes and point it to the seconds stored proc setting the parameters to be you #pYears parameter.
Now create your second parameter called #pTypes, make is multi-valued (I assume you want to select more than one type at a time in your final report). Set the available AND default values to point to dsTypes
That should be it. I've done this from memory so it might not be perfectly correct but hopefully close enough.

dynamic sql in SSRS

I have a dynamic SQL stored procedure returning multiple number of columns for different items.
For example, item1 - 5 columns, item2 - 4 columns
I am thinking of building SSRS reports using that stored procedure hoping to get multiple results.
For example, when click 'item1', it gives you that 5 columns sp can return whist click 'item2', it gives you that 4 columns sp can return
Can SSRS do this? When I use SP as a source for SSRS, it seems that the output is NOT dynamic as it only returns 'item1'
thanks
r
RS will read column metadata from the first result set of the query.
So I suggest you can add a table variable (fixed columns to support all your dynamic results) into your stored procedure, insert the dynamic query result into the table variable, and then select the result from the table variable.
what I did is to create a 'big table' in SSRS and manually create fields sp potentially returns and only display the columns based on the sp outputs by using 'viability' option
the only issue is that you need to manually configure each column to indicate under what circumstance it is supposed to appear

Looping through array in mysql stored procedure

I want to use arrays in mysql stored procedures.
i.e. array would look like
(0 =>array('name','value','value1'), 1=> array('name1','value2','value3))
I want to loop through each of them and perform some action on different tables. Can i do this ?
Stored Procedures do not accept arrays; you can, however, send as many input values as you want, as long as it matches the number and types of parameters declared in the stored procedure.
Hope this helps.
If you want to pass more then one item, then use additional (temporary) table instead of IN parameters.
If you need to pass items one by one - ('name','value','value1'), then use some IN parameters - (IN name VARCHAR(255), IN value1 INT(11), IN value2 INT(11))

Is there a way to call a function by its oid in postgresql?

I have a table with two enum columns, each enum contains about 10 possible values.
I need to write a function that calls a specific other function for each row of this table, depending on the particular combination of these values in the row. I don't want to create a 10x10 (=100) "WHEN"s and cases, what I want to do is to make a table that contains the combinations and the oids of correspoding functions. I even managed to do it, but now I don't know how to call the functions. Any help would be appreciated.
You can't call a function by it's oid. But you can of course get the functions name from the oid, and then construct a dynamic SQL statement and run it with EXECUTE in pl/pgsql.

MySQL stored procedure parameters

I want to grab x amount of items out of the DB, I was wondering if there was a way
of passing some list of numbers to a stored procedure to be used with WHERE IN?
SELECT item_id, item_description
FROM items
WHERE item_id IN ( NEED_LIST_OF_IDS_HERE );
Should I not use a stored procedure for this query and just build up the sql in the application?
Or should I make a seperate DB call for each single item_id?
NOTE: items is not the actual name of the table, so dont bash me for a poor name choice, Im just hiding implementation.
Poor unanswered question from a year ago...
If you weren't using an IN clause, you could certainly generate/prepare the sql inside the stored procedure and execute it there. It's harder to parameterize the IN clause.
How about passing in the list of ids, make a temp table inside your stored procedure, and then join over to the items table?