Forum Discussion
Use SQL Store Procedure in Power BI
Its a late reply, but it may help some body else, you can use openquery. Follwoing syntax will work with both import data and direct query
SELECT *
FROM OPENQUERY ([server name],
'EXEC dbname.dbo.spname @parametername = ''R1''');
- stangellapally10 years agoFrequent Visitor
I am having similar issue and tried both the solutions posted:
1. tried to change from Direct query to import but the Power BI doesnt give me that option to change.
2. Also tried the OPENQUERY OPTION and I am now getting the below message:
Details: "Microsoft SQL: Server 'sv375002\lt1201' is not configured for DATA ACCESS."
- Anonymous10 years agoNot applicable
stangellapallyeferreiranirajdubeyasocorro As a follow up to my previous post, i was testing this further due to another thread, and have discovered that you don't need to change any database settings or use OpenQuery. If you wrap your stored procedure in a variable you can import the data using a sproc (Doesn't work in Direct Query, only import)
example:
DECLARE @sqlCommand varchar(1000)
SET @sqlCommand = 'dbo.Testproc'
EXEC (@sqlCommand)- Baskarved10 years agoRegular Visitor
Small query over here,If we need to pass parameters to the procedure then how can we use this here?Could you share the syntax so that it would be helpful for beginners.
Thanks.
- Anonymous10 years agoNot applicable
1. tried to change from Direct query to import but the Power BI doesnt give me that option to change.
It is most likely because you already have a connection to a SQL source in Direct Query mode. If that is the case, I believe this gets greyed out.
2. Also tried the OPENQUERY OPTION and I am now getting the below message:
Details: "Microsoft SQL: Server 'sv375002\lt1201' is not configured for DATA ACCESS."
You would need to enable direct access on your SQL Server. You can check what it is currently set at by running this:
select server_id, name, is_data_access_enabled from sys.servers
But I would definitely check with your DB team (if you aren't) before switching anything.
To enable you would execute EXEC sp_serveroption '<Your ServerName>', 'DATA ACCESS', TRUE
After enabling that feature you will be able to successfully execute the OpenQuery.
As noted, be sure you understand what you are enabling and what it is doing before executing anything.
- ZhiqiangZhou10 years agoMicrosoft Employee
nirajdubey Thank you. I succeeded in using the SP by OpenQuery as you introduced.
- Zak28159 years agoRegular Visitor
nirajdubey, I can't for the life of me get this to work for Direct Query mode:
SELECT *
FROM OPENQUERY ([server name],
'EXEC dbname.dbo.spname @parametername = ''R1''');I've tried each of these below:
SELECT *
FROM OPENQUERY ([server name],
'EXEC dbname.dbo.spname @AsOfDate = ''GETDATE()''');SELECT *
FROM OPENQUERY ([server name],
'EXEC dbname.dbo.spname @AsOfDate = ''03-16-2017 23:59:59'' ');SELECT *
FROM OPENQUERY ([server name],
'EXEC dbname.dbo.spname @AsOfDate = CONVERT(DATETIME,''03-16-2017 23:59:59'',101) ');None seem to work. The times I can get a preview loaded, there's always an error on the "Apply".
Please help if anyone has succeeded in calling a Stored Proceedure in Direct Import Mode.