根据参数值

时间:2015-09-23 15:37:55

标签: sql-server reporting-services parameters ssrs-2008-r2 ranking

所以我在SSRS中有一个简单的表,有三列。第一个是Agent(调用处理程序的名称),第二个是由一个参数填充,该参数控制显示数据的6个可能列中的哪一个。构成数据集的查询如下:

SELECT CAST(Day AS DATE) AS 'Day'
, ISNULL(externalID, '**No Agent**') AS 'Agent'
, CAST((TalkTime + BreakTime + BusyonDNTime + BusyMiscTime + ConsultationTime + RingTime + Default_ACW + Wrap) / NULLIF ([Calls Ans], 0) AS DECIMAL(18, 2)) AS 'AHT'
, CAST([Comfort Break] / NULLIF (Logged, 0) AS DECIMAL(18, 6)) AS 'ComfortBreak'
, CAST([Designated Other] / NULLIF (Logged, 0) AS DECIMAL(18, 6)) AS 'DesignatedOther'
, CAST(Reflection / NULLIF (Logged, 0) AS DECIMAL(18, 6)) AS 'Reflection'
, CAST([System Failure] / NULLIF (Logged, 0) AS DECIMAL(18, 6)) AS 'SystemFailure'
, CAST(Skillset_Default_Activity_Code / NULLIF (Logged, 0) AS DECIMAL(18,6)) AS 'Skillset_Default_Activity_Code'
, [Short Calls Ans] AS 'ShortCallsAns'
, CASE WHEN CAST(([TalkTime] + [BreakTime] + [BusyonDNTime] + [BusyMiscTime] + [ConsultationTime] + [RingTime] + [Default_ACW] + [Wrap]) / NULLIF ([Calls Ans],0) AS DECIMAL(18, 2)) IS NULL
         AND CAST([Comfort Break] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Designated Other] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Reflection] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL AND CAST([System Failure] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Skillset_Default_Activity_Code] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL AND [Short Calls Ans] IS NULL
         THEN 0 
        ELSE 1 
        END AS DataFlag
FROM            PulseReportData
WHERE        (CAST(Day AS DATE) = @ActivityDate) AND 
                     ((CASE WHEN CAST(([TalkTime] + [BreakTime] + [BusyonDNTime] + [BusyMiscTime] + [ConsultationTime] + [RingTime] + [Default_ACW] + [Wrap]) / NULLIF ([Calls Ans],0) AS DECIMAL(18, 2)) IS NULL
         AND CAST([Comfort Break] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Designated Other] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Reflection] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL AND CAST([System Failure] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Skillset_Default_Activity_Code] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL AND [Short Calls Ans] IS NULL
         THEN 0 
        ELSE 1 
        END) = 1)

报告有一个名为@Field的参数,其值是上面列的列名(除了Date和Agent)。报表上的第二列数据文本框包含以下表达式;

=Fields(Parameters!Field.Value).Value

因此,在运行报告之前,从下拉列表中选择的任何列名都将显示在第二列中。

我无法弄清楚如何开始工作是这样的;

我需要添加一个参数,让用户可以选择5,10,20或50的排名,这些参数将显示前5个,10个,20个或50个代理,这些代理将根据以下任何一个数字返回的数字显示列被选中。我尝试将以下内容添加到数据集查询中;

ROW_NUMBER() OVER (partition BY @Field ORDER BY @Field DESC) AS rn

然后将列rn添加为报告中的第三列。然后我将一个过滤器应用于Tablix,以说明列rn<我创建的参数的值叫做@rank。其值为6,11,21& 51(总是高于实际排名值的数量,考虑到“小于”。虽然我想我可以使用< =)

发生的情况是代理列表和值显示在报表上,第3列中显示的正确排名值数量是从@rank下拉参数中选择的,但主列的值未排在降序排列。他们似乎是完全随意的。因此,我添加到数据集查询中的ROW_NUMBER列对参数内的列不感兴趣。我根本无法找到基于前5,10,20或50的那些排名值的方法:-S

1 个答案:

答案 0 :(得分:1)

有几种方法,最简单的方法就是向sql中添加两个参数,这些参数映射到所选列并返回所需的行数。诀窍是你可以在order by语句中使用别名,所以ComfortBreak的命令是完全可行的。在下面的示例中,我使用偏移提取来将更改隔离到结尾,以便更清楚地了解更改的内容,但选择顶部@RowCount也可以。

SELECT CAST(Day AS DATE) AS 'Day'
, ISNULL(externalID, '**No Agent**') AS 'Agent'
, CAST((TalkTime + BreakTime + BusyonDNTime + BusyMiscTime + ConsultationTime + RingTime + Default_ACW + Wrap) / NULLIF ([Calls Ans], 0) AS DECIMAL(18, 2)) AS 'AHT'
, CAST([Comfort Break] / NULLIF (Logged, 0) AS DECIMAL(18, 6)) AS 'ComfortBreak'
, CAST([Designated Other] / NULLIF (Logged, 0) AS DECIMAL(18, 6)) AS 'DesignatedOther'
, CAST(Reflection / NULLIF (Logged, 0) AS DECIMAL(18, 6)) AS 'Reflection'
, CAST([System Failure] / NULLIF (Logged, 0) AS DECIMAL(18, 6)) AS 'SystemFailure'
, CAST(Skillset_Default_Activity_Code / NULLIF (Logged, 0) AS DECIMAL(18,6)) AS 'Skillset_Default_Activity_Code'
, [Short Calls Ans] AS 'ShortCallsAns'
, CASE WHEN CAST(([TalkTime] + [BreakTime] + [BusyonDNTime] + [BusyMiscTime] + [ConsultationTime] + [RingTime] + [Default_ACW] + [Wrap]) / NULLIF ([Calls Ans],0) AS DECIMAL(18, 2)) IS NULL
         AND CAST([Comfort Break] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Designated Other] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Reflection] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL AND CAST([System Failure] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Skillset_Default_Activity_Code] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL AND [Short Calls Ans] IS NULL
         THEN 0 
        ELSE 1 
        END AS DataFlag
FROM            PulseReportData
WHERE        (CAST(Day AS DATE) = @ActivityDate) AND 
                     ((CASE WHEN CAST(([TalkTime] + [BreakTime] + [BusyonDNTime] + [BusyMiscTime] + [ConsultationTime] + [RingTime] + [Default_ACW] + [Wrap]) / NULLIF ([Calls Ans],0) AS DECIMAL(18, 2)) IS NULL
         AND CAST([Comfort Break] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Designated Other] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Reflection] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL AND CAST([System Failure] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL 
         AND CAST([Skillset_Default_Activity_Code] / NULLIF ([Logged], 0) AS DECIMAL(18, 6)) IS NULL AND [Short Calls Ans] IS NULL
         THEN 0 
        ELSE 1 
        END) = 1)
order by @SelectedColumn /* acs/desc whatever is appropriate */
offset 0 rows fetch next @RowsReturned only