1

我在 SSRS 中遇到了一个奇怪的错误,在一个带有许多下拉参数的报告(它被放入一个存储过程中)中:

Query execution failed for dataset 'DataSet1'.

Must pass parameter number 3 and subsequent parameters as '@name = value'. After the form '@name = value' has been used, all subsequent parameters must be passed in the form '@name = value'

我对这里发生的事情一无所知 - 是什么意思@name = value

我在网上搜索,有人提到你应该改变存储过程?

这是我的存储过程的上半部分的外观:

USE [FederatedSample]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



ALTER PROCEDURE [dbo].[prc_RPT_Select_BI_Completes_Data_View_2]


    @FromDate DATETIME,
    @ToDate DATETIME,

    @AccountIDs VARCHAR(max) = null,
    @ClientIDs VARCHAR(max) = null,
    @SupplierIDs VARCHAR(max) = null,

    @CompleteType INT = NULL,
    /*
     * 0 - Routed
     * 1 - Targeted
     * 2 - Offerwall
     */

    @SourceType BIT = NULL,
    /*
     * Works if @AccountID is not null
     * (should only be used if @AccountID has a single value)
     *
     * 0 - Owned by @AccountID
     * 1 - External (not owned by @AccountID)
     */

    @SurveyStatus INT = NULL,
    /*
     * NULL - All Surveys
     * 0 - Completes Approved Surveys
     * 1 - Invoiced Surveys
     */

    @IsSupplierUser BIT = 0
    /*
     * used to decide whether to display FEDSurveyName or SupplierSurveyName
     */
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @SQL NVARCHAR(MAX) = N'',
            @Params NVARCHAR(MAX)

    IF @AccountIDs is not null
    BEGIN
        SET @SQL += N'DECLARE @AccountIDs VARCHAR(MAX) = @pAccountIDs; '
    END

    IF @ClientIDs is not null
    BEGIN
        SET @SQL += N'DECLARE @ClientIDs VARCHAR(MAX) = @pClientIDs; '
    END

    IF @SupplierIDs is not null
    BEGIN
        SET @SQL += N'DECLARE @SupplierIDs VARCHAR(MAX) = @pSupplierIDs; '
    END

    SET @SQL +=  N'
        SELECT   bi.SupplierID as ''Supplier ID''
                ,bi.SupplierName as ''Supplier Name''

                ,bi.PID as ''PID''
                ,bi.RespondentID as ''Respondent ID''

                ,lk_slt.Name as ''Entry Link Type''

                ,ts.SurveyNumber as ''Initial Survey ID'''

稍后在存储过程中。它会做这样的事情来分割字符串:

IF @AccountIDs is not null 
BEGIN
    SET @SQL += CHAR(13) + CHAR(9)
    SET @SQL += N' and bi.AccountID in (SELECT CAST(val as INT) FROM dbo.Split(@AccountIDs, '','

在此处输入图像描述

4

1 回答 1

2

调用存储过程时,您可以按位置(不是一个好主意)或按名称(恕我直言,更好的方法)传递参数。

EXEC dbo.MyStoredProcedure '12/31/2012', 1;  -- Not a great way to pass parameters 

EXEC dbo.MyStoredProcedure @AsOfDate = '12/31/2012', @AccountID = 1; -- A better way

从您收到的错误消息中,我怀疑 SSRS 正在使用第二种方法,并且在将第三个参数提供给存储过程时遇到了问题。

如果没有更多信息,很难为您提供错误的准确解释(存储过程可能会有所帮助),有根据的猜测是提供参数的方式Account IDs, Client IDs and Supplier IDs并不完全正确。具体来说,我认为问题可能在于您提供了多个用逗号分隔的标识符。

您可以尝试传递一个帐户 ID、客户 ID 和供应商 ID,以查看您是否仍然收到错误。我还会尝试查看存储过程(或与编写它的 DBA \ Developer 交谈)以确定存储过程的预期用途。

于 2013-01-29T01:53:42.967 回答