Я пытаюсь ввести хранимую процедуру из SQL Server для использования в Power BI для панелей мониторинга и отчетов.Я получаю следующее сообщение об ошибке:
Подробности: "Microsoft SQL: Ошибка преобразования типа данных nvarchar в bigint."
Мы используем хранимую процедуру практически для всех нашихОтчеты в Jaspersoft без проблем.
В чем здесь проблема?
DECLARE @temp1 VARCHAR(max)
DECLARE @res NVARCHAR(max)
DECLARE @sub NVARCHAR(max)
DECLARE @fields NVARCHAR(max)
SET @temp1= '$P!{ProjectID}'
EXEC stored_procedure
@ListOfProjects = @temp1,
@wbs1 = 1,
@wbs2 = 1,
@groupCode1 =1,
@groupCode2 =1,
@groupCode3 =1,
@groupCode4 =1,
@groupCode5 =1,
@groupCode6 =1,
@groupCode7 =1,
@groupCode8 =1,
@groupCode9 =1,
@ResultSqlQuery = @res output
--EXECUTE sp_executesql @res
РЕДАКТИРОВАТЬ: Вот код для хранимой_процедуры
USE [Database]
GO
/****** Object: StoredProcedure [stored_procedure] Script Date: 4/25/2019 10:45:11 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[stored_procedure]
@ListOfProjects nvarchar(max),
@wbs1 bit = 0,
@wbs2 bit =0 ,
@groupCode1 bit =0 ,
@groupCode2 bit =0 ,
@groupCode3 bit =0,
@groupCode4 bit =0 ,
@groupCode5 bit =0,
@groupCode6 bit =0 ,
@groupCode7 bit =0,
@groupCode8 bit =0,
@groupCode9 bit =0,
@ResultSqlQuery nvarchar(max) ='' OUTPUT
AS
SET NOCOUNT ON;
DECLARE @CurrentProjectId nvarchar(max)
DECLARE @TotalCount INT;
DECLARE @Counter INT;
DECLARE @ResultString nvarchar(max);
DECLARE @Temp nvarchar(max);
SET @Counter = 0;
SET @ResultString = '';
SET @TotalCount = 0;
SET @TotalCount = ( SELECT count(*) FROM dbo.ufn_split_string(@ListOfProjects) ) ;
WHILE @Counter < @TotalCount
BEGIN
SET @CurrentProjectId = ( SELECT CAST(ColumnData AS BigInt)FROM dbo.ufn_split_string(@ListOfProjects) where row = @Counter )
--PRINT @CurrentProjectName
IF @Counter <> 0
BEGIN
SET @ResultString = @ResultString + +' UNION ALL '
END
EXECUTE stored_procedure2 @PrjId = @CurrentProjectId ,
@wbs1 = @wbs1,
@wbs2 = @wbs2 ,
@groupCode1 =@groupCode1 ,
@groupCode2 =@groupCode2 ,
@groupCode3 =@groupCode3 ,
@groupCode4 =@groupCode4,
@groupCode5 =@groupCode5 ,
@groupCode6 =@groupCode6,
@groupCode7 =@groupCode7,
@groupCode8 =@groupCode8,
@groupCode9 =@groupCode9,
@SqlQuery = @Temp OUTPUT;
SET @ResultString = @ResultString + ' (' + @Temp +') '
SET @Counter = @Counter+1
END
SET @ResultSqlQuery = @ResultString
RETURN
--EXECUTE sp_executesql @ResultString