I need to build a report in Power BI. I can get the data for the report by calling the MS SQL Server stored procedure with parameters. Question: How can I pass dynamic parameters from a report to a stored procedure call? And the second question: one of the parameters is the user login. How to get it in Power BI and transfer the stored procedure call parameter to?
Go to query editor, and create the required parameters (from manage parameters)
Now create a new query that calls SQL procedure, you can pass hardcoded parameters for now.
Once data are imported, go to advance editor and replace the hard-coded parameter in the query part with the parameter you created, you will have to concat it.
refer: https://www.c-sharpcorner.com/article/execute-sql-server-stored-procedure-with-user-parameter-in-power-bi/
Related
I was trying to execute Snowflake stored procedures in Qlik Data Editor.
Snowflake stored procedures starts with CALL statement. But it will not return tabular result directly. I get a message, and we have select those results to get tabular result. I was not able to store the result message of CALL statement.
Please can anyone help how to execute a Snowflake stored procedure?
EX:
CALL "ODS_BI".Dimension('SK0009', 'DEBIT', 1, NULL);
You need to use RESULT_SCAN to retrieve the results from calling a stored procedure.
As example:
CALL <stored_proc_name>();
Retrieve result set:
SELECT * FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
For more information read here.
if you want to return a usable dataset then you might need to look at UDFs rather than SPs.
If you have to use a SP then this documentation explains the options available to you: Stored Procedure Overview
Looking for some help with this as me and my 'Mentor' are having some issues with resolving the problem
I have a stored procedure in SQL Server 2016 that works fine when dates are entered. However I need an Excel sheet to execute the stored procedure, which currently is also working fine.
The issue is when I'm trying to use a parameter with Excel to pass through the dates to the SQL query/stored procedure that I need to bring back. I'm struggling to link the two up to each other
The second answer here by mono código > how to pass parameters to query in SQL (Excel) - should work for me, however when I get to the part which explains 'The code in the next section assumes that you already have a parameter in your query (Connection Properties->Definition->Command Text) in the form “WHERE (DB_TABLE_NAME.Field_Name = ‘Default Query Parameter')” (including the parentheses). Clearly “DB_TABLE_NAME.Field_Name” and “Default Query Parameter” will need to be different in your code'
I'm unsure if this is due I just simply do not know how to write this part, or it's to do with how I'm trying to link up the cells within excel to the parameters within SQL
For some more context, the parameters are dates - to and from, which will be in an excel sheet, which will then feed through to a query, which is where the execute code for the stored procedure is.
If any help or guides or walkthrough's could be given I'd very much appreciate them!
Thanks,
Wil-Liam
My application used Spring MVC+iBatis+JBoss7+MySQL. I have a stored procedure in mySQL, mapped it in my iBatis mapper.xml file and calling it via my sqlMapClient from my DAO.
If i execute the dao method once it works fine, but if i execute two calls to the same method with different stored procedure parameters(change in parameter means change in the result columns in my stored procedure), I get an exception that says my sql gramer is wrong. Looking at the logs i find that iBatis is trying to map my first query columns (result of my initial method call) to my result map. I even tried printing the hashcode of my dao class instance and they are different. Why is this happening when the procedure executes just fine when tried from DB clients like DbVislaulizer
For information I am using a HashMap as my resultclass in my mapper.xml. This returns me a list of linkedhashmaps in my dao..
Any help would be really handy.
Thanks in advance
Fixed it. Have to set the property remapResults="true" in mapper.xml
Eg
select id="myReport" parameterClass="Map" resultClass="java.util.LinkedHashMap" remapResults="true"
I already have a code generator based on SQL DMO, that writes the a C# function for any stored procedure in by SQL Server 2008 database. Currenly however the code generator can only handle stored procedures that have input and output parameters. For stored procedures that return multiple records, the code generator returns a datatable with rows that each represent a output record.
Is there a way using SQL DMO to determine the fields that would be returned by a stored procedure if the output of a stored procedure is select * from Member where MemberID=1?
Thanks
My guess is that you cannot do this in DMO, since DMO relies on meta information stored in SQL Server, and the result set description of an SP is not stored in that way (as far as I know).
What you can do, however, is to have your generator execute the stored procedure inside a transaction, and analyze the resulting SqlDataReader. Have a look at the GetName(), GetFieldType() and GetSchemaTable() methods to construct your result class.
After execution, rollback the transaction (in case the SP makes any changes to the database).
You also might consider upgrading your generator to SMO, as MSDN states that DMO will not be supported in the future.
I am trying to create an SSIS package that queries data from a table, and calls a stored procedure in another database with each row.
In my old DTS package, I was doing this:
EXEC myStoredProcedure ?, ?, ?
...and then I mapped the parameters. However, in SSIS, I can't figure out how to make this work.
I have a Data Flow task, which first runs a query for the data. It passes the data to an OLE DB Destination. I set the Data access mode to "SQL command", but when I try to put in the SQL above, I get "Invalid Parameter Count" when it parses the SQL. I can't get to the Mappings screen. Any ideas?
In the Data Flow, the OLE DB Command can be used to execute a SQL statement for each row in a dataflow - (MSDN documentation)
Alternatively, you can store the source result set in a variable of data type object and use a Foreach Loop container in the Control Flow (example here).
You will need to use an Execute SQL Task. In the SQLStatement section you can add the code to execute the stored procedure.
In order to pass in parameters, use the ? syntax and specify the parameters in the "Parameter Mapping" section.
A good example can be found here.