Forum Discussion
Anonymous
6 years agoNot applicable
multiple table reports from run one stored procedure
I posted original question in https://community.powerbi.com/t5/Desktop/SQL-Stored-Procedure-with-2-result-sets/td-p/1149559 But did not get any clear reply to it so I am following up now. bas...
rishab
5 years agoRegular Visitor
Okay, here's how I solved it at my work (I needed to import data from 1 Stored Proc, which provided 2 outputs):
- Considerations for the SQL side:
- Create a passable variable "@Worksheet" in your Stored Proc. I'm guessing that for you, the start of your stored proc will look something like this:
ALTER PROCEDURE mystoredproc
--@TodaysDate datetime, -- Add date or other parameters as needed
@WorkSheet INT -- This parameter will help you "break" each output
AS
- Break each output section/select statement as follows:
IF @Worksheet = 1
BEGIN
SELECT * FROM yabbadabbadooDatabase
END
ELSE IF @Worksheet = 2
BEGIN
SELECT * FROM benandjerryDatabase
END - Here's how your exec statement will look like:
- exec mystoredproc 1
- exec mystoredproc 2
- Considerations on the Power BI side (you probably know most of this stuff anyway, based on your comments above):
- Import SQL Server data
- Add Server and Database names as needed.
- Select "Import" under "Data Connectivity mode"
- Write the execute query for stored proc for only the 1st output:
- exec mystoredproc 1
- Transform/load the data as needed.
- Repeat steps 1-5 for 2nd output:
- exec mystoredproc 2
This will create 2 datasets in your Power BI file, which can be updated by clicking the "Refresh" button.
I hope this finally helps you 🙂
I noticed that other answers weren't as useful here either, nor in your original post. Thankfully someone at work showed me it, and it works for me.