简体   繁体   English

如何获取SSRS报告以显示0个值

[英]How to get an SSRS report to show 0 values

I have an SSRS report which is presenting a count on the amount times some particular options are chosen from a table in access. 我有一个SSRS报告,该报告显示了从访问表中选择某些特定选项的次数。

For example, of these 100 records not necessarily every option has been picked, let's say the breakdown is as follows 例如,在这100条记录中,不一定每个选项都已被选中,细分如下

  • Option a 32 选项a 32
  • Option b 28 选项b 28
  • Option c 0 选项c 0
  • Option d 0 选项d 0
  • Option e 40 选件e 40
  • Options fj 0 选项fj 0

When I run my report it will then only give me the rows of Option a,b and e but how do I get to show all 10 options even the ones with 0 values? 当我运行报表时,它只会给我选项a,b和e的行,但是我如何显示所有10个选项,甚至是0值的选项呢?

Update: This is the code that the query pulls the data from 更新:这是查询从中提取数据的代码

SELECT Agent, Team, First_Choice_Options, Start_Time FROM Record 
 WHERE (Start_Time >= CONVERT(DATE, @Startdate)) 
   AND (Start_Time < CONVERT(DATE, DATEADD(DAY, 1, @Enddate))) 
   AND (Team = 'Triage') AND (Agent IN (@Agent))

This is really a SQL thing, nothing specific to Reporting Services. 这确实是SQL问题,没有Reporting Services特有的内容。 SSRS will only display what is returned from the data source. SSRS将仅显示从数据源返回的内容。 So, you need to change up your query to return the options that are not getting any activity. 因此,您需要更改查询以返回没有任何活动的选项。 An example is below. 下面是一个示例。 The SELECT statement toward the bottom is where the trick is; 窍门就在底部的SELECT语句中。 the LEFT JOIN does this for you. LEFT JOIN为您做到这一点。 Everything else is just to get the code to work so I could test this. 其他一切只是为了使代码正常工作,因此我可以对此进行测试。

CREATE TABLE Record (Agent varchar(30), 
    Team varchar(30), 
    First_Choice_Options varchar(30), 
    Start_Time datetime);

INSERT INTO Record VALUES ('Some Agent','Triage','Option A','2016-06-05'),
    ('Some Agent','Triage','Option A','2016-06-10'),
    ('Some Agent','Triage','Option B','2016-06-15'),
    ('Some Agent','Triage','Option B','2016-06-20'),
    ('Some Agent','Triage','Option A','2016-06-25')

CREATE TABLE Options (First_Choice_Options varchar(30))

INSERT INTO Options VALUES ('Option A'),('Option B'),('Option C'),('Option D')

DECLARE @Startdate datetime = '2016-06-01',
    @Enddate datetime = '2016-06-30',
    @Agent varchar(30) = 'Some Agent'

SELECT O.First_Choice_Options AS Options, SUM(IIF(R.First_Choice_Options IS NULL, 0, 1)) AS Options_Count 
FROM Options O LEFT JOIN Record R
ON O.First_Choice_Options = R.First_Choice_Options
AND (Start_Time >= CONVERT(DATE, @Startdate)) 
    AND (Start_Time < CONVERT(DATE, DATEADD(DAY, 1, @Enddate))) 
    AND (Team = 'Triage') AND (Agent IN (@Agent))
GROUP BY O.First_Choice_Options

DROP TABLE Record
DROP TABLE Options

If you run this against a testing database, you will see what the result look like. 如果对测试数据库运行此命令,则将看到结果。 Option A and B will have counts, option C and D will report 0 (zero) for the count. 选项A和B将具有计数,选项C和D将报告该计数为0(零)。 This code assumes you have some sort of Options like table in your data source. 此代码假定您的数据源中有一些类似表的选项。

Options                        Options_Count
------------------------------ -------------
Option A                       3
Option B                       2
Option C                       0
Option D                       0

Good luck! 祝好运!

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

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