简体   繁体   English

SSRS数据集不要求参数值

[英]SSRS DataSet not Asking for Parameter Values

Today, While working with SSRS, i got an amazing Problem there. 今天,在与SSRS合作时,我遇到了一个了不起的问题。 I'm still not being able to findout what the problem is all about. 我仍然无法找出问题所在。 Well, I've an Stored Procedure : 好吧,我有一个存储过程:

ALTER PROCEDURE [dbo].[S_MEMBER_DROP_OUT_REPORT](@DTNAME VARCHAR(50),
                                                 @BRCODE VARCHAR(3),
                                                 @F_DATE VARCHAR(10),
                                                 @T_DATE VARCHAR(10),
                                                 @CLOSECODE VARCHAR(50),
                                                 @CENTRALIZED VARCHAR(3))
WITH RECOMPILE
AS BEGIN

SET NOCOUNT ON;
DECLARE @DTBASE VARCHAR(50)
DECLARE @CLOSEOPT VARCHAR(50)
SET @DTBASE=''

IF @CENTRALIZED='YES'
    SET @DTBASE = @DTNAME
ELSE
    SET @DTBASE = Left(@DTNAME, 13) + @BRCODE

IF @CLOSECODE ='0'
    BEGIN
        Exec (' 
                SELECT T1.CENTER_CODE + '' - '' + CTR.CENTER_NAME AS CENTER,COUNT(DISTINCT T1.CUSTOMER_CODE) AS CNT 
                FROM 
                    (SELECT * FROM CENTER W WHERE BR_CODE='''+@BRCODE+''') AS CTR,
                    (SELECT A1.CENTER_CODE,A1.CUSTOMER_CODE,A2.CLOSE_CODE,A2.CLOSE_DESC_CODE,MAX(A2.CLOSE_DATE) AS REDG_DATE,MAX(A2.TRAN_ID) AS TRAN_ID FROM '+@DTBASE+'.dbo.CENTER_GROUP_MEMBER AS A1, '+@DTBASE+'.dbo.CUST_REDG_HIST A2,'+@DTBASE+'.dbo.CUST_STATUS_HIST A3
                        WHERE A2.CUST_STATUS_CODE=''04'' AND A2.CLOSE_CODE<>''03'' 
                        AND A1.BR_CODE='''+@BRCODE+''' AND A2.BR_CODE='''+@BRCODE+'''
                        AND (A2.CLOSE_DATE BETWEEN '''+@F_DATE+''' AND '''+@T_DATE+''')
                        AND A1.CUSTOMER_CODE=A2.CUSTOMER_CODE 
                        AND A1.CUSTOMER_CODE=A3.CUSTOMER_CODE AND A1.CENTER_CODE=A3.CENTER_CODE AND A1.GROUP_CODE=A3.GROUP_CODE
                        AND A3.TRAN_ID=(SELECT TOP 1 TRAN_ID FROM '+@DTBASE+'.dbo.CUST_STATUS_HIST CSH WHERE A3.CUSTOMER_CODE=CSH.CUSTOMER_CODE ORDER BY TRAN_ID DESC)
                    GROUP BY A1.CENTER_CODE,A1.CUSTOMER_CODE,A2.CLOSE_CODE,A2.CLOSE_DESC_CODE
                    ) AS T1 
                WHERE T1.CENTER_CODE=CTR.CENTER_CODE
                GROUP BY T1.CENTER_CODE,CTR.CENTER_NAME
                ORDER BY T1.CENTER_CODE
             ') 
    END
ELSE
    BEGIN       
        IF LEN(@CLOSECODE) > 0 SET @CLOSEOPT=' AND A2.CLOSE_CODE IN ('+@CLOSECODE+')' ELSE SET @CLOSEOPT=''
        Exec (' 
                SELECT T1.CENTER_CODE + '' - '' + CTR.CENTER_NAME AS CENTER,CCC.CLOSE_NAME,CCD.CLOSE_DESC_NAME AS CLOSE_DESC,COUNT(DISTINCT T1.CUSTOMER_CODE) AS CNT FROM 
                    (SELECT * FROM '+@DTBASE+'.dbo.CUST_CLOSE_CAUSE) AS CCC,
                    (SELECT * FROM '+@DTBASE+'.dbo.CUST_CLOSE_DESC) AS CCD,
                    (SELECT * FROM CENTER WHERE BR_CODE='''+@BRCODE+''') AS CTR,
                    (SELECT A1.CENTER_CODE,A1.CUSTOMER_CODE,A2.CLOSE_CODE,A2.CLOSE_DESC_CODE,MAX(A2.CLOSE_DATE) AS REDG_DATE,MAX(A2.TRAN_ID) AS TRAN_ID FROM '+@DTBASE+'.dbo.CENTER_GROUP_MEMBER AS A1,'+@DTBASE+'.dbo.CUST_REDG_HIST A2,'+@DTBASE+'.dbo.CUST_STATUS_HIST A3
                        WHERE A2.CUST_STATUS_CODE=''04'' '+@CLOSEOPT+'
                        AND A1.BR_CODE='''+@BRCODE+''' AND A2.BR_CODE='''+@BRCODE+'''
                        AND (A2.CLOSE_DATE BETWEEN '''+@F_DATE+''' AND '''+@T_DATE+''')
                        AND A1.CUSTOMER_CODE=A2.CUSTOMER_CODE 
                        AND A1.CUSTOMER_CODE=A3.CUSTOMER_CODE AND A1.CENTER_CODE=A3.CENTER_CODE AND A1.GROUP_CODE=A3.GROUP_CODE
                        AND A3.TRAN_ID=(SELECT TOP 1 TRAN_ID FROM '+@DTBASE+'.dbo.CUST_STATUS_HIST CSH WHERE A3.CUSTOMER_CODE=CSH.CUSTOMER_CODE ORDER BY TRAN_ID DESC)
                    GROUP BY A1.CENTER_CODE,A1.CUSTOMER_CODE,A2.CLOSE_CODE,A2.CLOSE_DESC_CODE
                    ) AS T1 
                WHERE T1.CLOSE_DESC_CODE =CCD.CLOSE_DESC_CODE 
                AND T1.CLOSE_CODE =CCC.CLOSE_CODE 
                AND T1.CENTER_CODE=CTR.CENTER_CODE
                GROUP BY T1.CENTER_CODE,CCD.CLOSE_DESC_NAME,CCC.CLOSE_NAME,CTR.CENTER_NAME 
            ')  
    END
END

GO

The above Stored Procedure asks for a Parameter Named CLOSECODE , and based on the value provided, eg '0' or '01' or '02' it returns the desired fields from the appropriate table. 上面的存储过程要求输入一个名为CLOSECODE的参数,并根据所提供的值(例如'0'或'01'或'02')从适当的表中返回所需的字段。 Returned fields vary on that parameter. 返回的字段因该参数而异。

When I define a dataSet in SSRS like the following: 当我在SSRS中定义数据集时,如下所示:

数据集截图

It is not asking for any parameter values and it is producing the following fields by default: 它不要求任何参数值,并且默认情况下会产生以下字段:

结果截图

I tried all the things that comes into my mind that what the problem is about. 我尝试了所有我想出的问题所在。 But still could not Solve this. 但是仍然无法解决这个问题。 And, actually, Im wondered, why the SSRS is Behaving like that Today. 而且,实际上,我想知道SSRS今天的行为为何如此。 Im working With it Since 2-3 Months and I've so far designed lot of Reports like that, which contain the Dynamic Query, Fields from the Stored Procedure but there was no any problem, but this one. 我从2-3个月开始使用它,到目前为止,我已经设计了很多类似报告,其中包含动态查询,存储过程中的字段,但没有任何问题,但是这是一个问题。

When SSRS determines fields for SP Datasets (at least up to 2008R2), it will call the underlying SP with SET FMTONLY ON . 当SSRS确定SP数据集的字段(至少到2008R2为止)时,它将使用SET FMTONLY ON调用基础SP。 This only returns the resultset metadata, not all the data. 这仅返回结果集元数据,而不是所有数据。

It seems like SSRS determines whether asking for parameters is required - it seems not in your case. 似乎SSRS决定是否要求输入参数-在您的情况下似乎不需要。 In my experience I only get prompted when temp tables are involved in the SP - I have been unable to find any explanation here. 以我的经验,仅当临时表包含在SP中时,我才会得到提示-我在这里找不到任何解释。

The problem with your Dataset is that there are two possible sets of columns returned from the SP, and it's only getting the first one, which only returns two columns - this is what you're seeing above. 您的数据集的问题在于,从SP返回的列可能有两套,而只获得了第一组,只返回了两列-这就是您在上面看到的。 SSRS just hits the first return point, which has two columns, and ignores any other possible select statements. SSRS只是到达第一个返回点,该返回点有两列,并且忽略了任何其他可能的select语句。

Ignoring why you're not being asked to enter parameters (again, this is not unusual for me), I can think of a couple of options: 忽略为什么不要求您输入参数(同样,这对我来说并不常见),我可以想到几个选择:

1: Adjust your SP to make sure whatever statement is run, the same columns are always returned. 1:调整您的SP以确保运行任何语句,始终返回相同的列。

So, in you first possible statment, I would change 所以,在你第一个可能的陈述中,我会改变

IF @CLOSECODE ='0'
    BEGIN
        Exec (' 
                SELECT T1.CENTER_CODE + '' - '' + CTR.CENTER_NAME AS CENTER
                  ,COUNT(DISTINCT T1.CUSTOMER_CODE) AS CNT 
                FROM

To include all the required columns - that way SSRS will always get the correct metadata. 要包括所有必需的列-这样,SSRS将始终获得正确的元数据。 So something like: 所以像这样:

IF @CLOSECODE ='0'
    BEGIN
        Exec (' 
                SELECT T1.CENTER_CODE + '' - '' + CTR.CENTER_NAME AS CENTER
                  ,COUNT(DISTINCT T1.CUSTOMER_CODE) AS CNT
                  ,CAST(NULL AS VARCHAR(100)) AS CENTER
                  ,CAST(NULL AS VARCHAR(100)) AS CLOSE_NAME
                  ,CAST(NULL AS VARCHAR(100)) AS CLOSE_DESC
                  ,... -- Extra columns as required
                FROM

2: Add in missing columns in manually. 2:手动添加缺少的列。

You can just add more columns into the Dataset manually in the Designer: 您可以在设计器中手动将更多列添加到数据集中:

在此处输入图片说明

Short Answer: put first result set into a #TempTable in your proc, and it then starts prompting for the Parameters in SSRS again! 简短的答案:将第一个结果集放入proc的#TempTable中,然后再次开始提示SSRS中的参数!

Long Answer: I have written HUNDREDS of Proc's for SSRS reports where we use a Parameter to control what dataset is being output to the report, so we can have multiple data sets in the report, as well as have the parameters and data pull from the same proc. 长答案:我为SSRS报告编写了数百份Proc,其中我们使用参数来控制向报告输出的数据集,因此我们可以在报告中拥有多个数据集,并具有从同样的过程。 So the Proc and report are looping back an forth to provide the data. 因此,Proc和报表正在循环返回以提供数据。 In that case, when you hit REFRESH Fields, it should ask you for the parameter of control (ours is called @DatasetFlag) So in that case, I put "Dataset1" in @DatasetFlag, and in the proc, we have IF @DatasetFlag = "Dataset1" Begin xxxxx End ELSE If @DatasetFlag = "Dataset2" Begin END ESLE and so on... Here is where SSRS if funky. 在这种情况下,当您单击REFRESH字段时,它应该询问您控制的参数(我们称为@DatasetFlag)。在这种情况下,我将“ Dataset1”放在@DatasetFlag中,在proc中,我们有IF @DatasetFlag =“ Dataset1”开始xxxxx结束ELSE如果@DatasetFlag =“ Dataset2”开始END ESLE,以此类推...这是SSRS的地方(如果很时髦)。 SOMETIMES it asks for the parameters, sometimes it does not, in that case (not asking) it will just grab the first result set and use those fields! 有时它会询问参数,有时不询问,在这种情况下(不询问),它将只获取第一个结果集并使用这些字段! or better yet just stay empty! 或更好,但保持空虚!

I did find a hint at a possible solution to FORCE it to ask, and it does work! 我确实找到了一种强制解决方案的提示,它确实有效!

You have to Select your data into a TEMP Table (ie #temptable1) and then it will start asking again! 您必须将数据选择到TEMP表(即#temptable1)中,然后它将再次开始询问! So at least the FIRST result set has to use a TEMP table, and then at that point, it does pull the proper fields list from the @DatasetFlag variable. 因此,至少FIRST结果集必须使用TEMP表,然后才从@DatasetFlag变量中提取适当的字段列表。

My new routine is to copy this to the start of my proc... 我的新例程是将其复制到我的过程的开始...

If (@Datasetflag = "Dummy") Begin Select getdate() as DummyDate into #TempDummy 如果(@Datasetflag =“ Dummy”)开始,请选择getdate()作为DummyDate到#TempDummy

Select DummyDate from #TempDummy

end ELSE.... The real if's then start here... 结束ELSE...。真正的if从这里开始...

This forces the REFRESH FIELDS to always ASK for a Parameter, which then pulls the fields in dynamically and lets me create reports much faster... no hand typing 50+ field entries! 这将强制REFRESH FIELDS始终询问参数,然后动态拉入字段并让我更快地创建报告...无需手动输入50多个字段条目!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM