SSRS中的“后续参数”错误?

时间:2013-01-29 00:43:15

标签: sql reporting-services ssrs-2008

我在SSRS中遇到一个奇怪的错误,在一个报告中(它被放入一个sproc中)有很多下拉参数:

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, '','

enter image description here

1 个答案:

答案 0 :(得分: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交谈)以确定存储过程的预期用法。