我想利用已经编写的存储过程,其中包含参数和临时表,以及Power BI(DirectQuery)的报告。
我试图通过表值函数来实现,如下所示:
CREATE FUNCTION [rpt].[ufnPBI0002_KPI]
(@YearMonth nvarchar(20), -- = '2017-12'
@Products nvarchar(50), -- = '2,7,8'
@Regions nvarchar(50) -- = '1'
)
-----------------------------------------------------------------------
-- Return type
-----------------------------------------------------------------------
RETURNS TABLE
-----------------------------------------------------------------------
-- Begin
-----------------------------------------------------------------------
AS
BEGIN
-----------------------------------------------------------------------
-- Declare return table
-----------------------------------------------------------------------
DECLARE @Result AS TABLE
(
SalesRegionId INT
,TotalCAcount INT
,EffectiveCAcount INT
,NewCA INT
,Plan_Total_CA_count INT
,Plan_eCA_Count_All INT
,Plan_CA_Intake INT
,Plan_CA_PJ_count INT
,Plan_NV_Prod_PJ INT
,Plan_Avg_NV_All_per_eCA INT
,BusinessLoanSpecialistCount INT
,ProfiJuniors INT
,ActiveCAcount INT
,TerminatedCAcount INT
,NewNV INT
,NewNVPJ INT
,AvgNVeCA INT
,AvgNVProfiJuniors INT
)
--------------------------------------------------------------------------
-- Handle stored procedure result
--------------------------------------------------------------------------
INSERT INTO @Result
EXEC [rpt].[MR0002_KPI] @YearMonth, @Products, @Regions
--------------------------------------------------------------------------
-- Return the result
--------------------------------------------------------------------------
SELECT * FROM @Result
RETURN;
-----------------------------------------------------------------------
-- END
-----------------------------------------------------------------------
END
返回
Msg 102,Level 15,State 31,Procedure ufnPBI0002_KPI,Line 68 [Batch Start Line 0]
附近的语法不正确
'BEGIN'
我认为从TFV调用存储过程是不可能的,但是非常感谢任何提示,如何利用PBI的参数化存储过程。
答案 0 :(得分:1)
答案 1 :(得分:0)
说到SSRS数据源,你不必在你的情况下使用函数,bit可以直接使用存储过程:
EXEC [rpt].[MR0002_KPI] @YearMonth, @Products, @Regions
只需刷新数据集,它就应该能够检测SP返回的可用列。
此外,您的初始方法将导致(如果TVM允许SP)对@Result表变量进行不必要的插入,因此可能会导致TEMPDB上的额外负载