简体   繁体   English

将SSRS参数转换为Null

[英]Convert SSRS parameter to Null

I have SSRS report that showing Marketing Features. 我有SSRS报告显示营销功能。 we have in the MF a field called "Test", the values are "PSI 1" or PSI 2" and also the field can be empty. 我们在MF中有一个名为“测试”的字段,值是“ PSI 1”或“ PSI 2”,该字段也可以为空。

I added a dataset for the Test parameter with this query: 我为此查询添加了Test参数的数据集:

SELECT DISTINCT Corp_Test
  FROM [Tfs_Warehouse].[dbo].[CurrentWorkItemView]
 WHERE ProjectNodeGUID = @ProjectGuid
   AND System_WorkItemType = 'Marketing Feature'
UNION
SELECT 'Null'
ORDER BY Corp_Test

Now in the report, the values are PSI 1 PSI 2 and Null : 现在在报告中,值是PSI 1 PSI 2Null

在此处输入图片说明

In the Main Query I filtered the results according to the parameter like this: 在主查询中,我根据如下参数过滤结果:

where COALESCE(Corp_Test, 'Null') IN (@TestParam)

The report works fine, and if I selected all values I get also Marketing Features with empty Test field. 该报告运行良好,如果我选择了所有值,我还将获得带有空白“测试”字段的“营销功能”。

My question is: 我的问题是:

Instead of Null on the dropdown, I want it to be written No PSI and actually in the main query it will be Null. 而不是下拉菜单中的Null ,我希望将其写为No PSI ,实际上在主查询中它将是Null。 is it possible? 可能吗?

In your parameter properties, on the Available Values screen you will see an option for the Value and the Label . 在参数属性的“ Available Values屏幕上,您将看到“ Value和“ Label的选项。 This allows you to show one thing to the end user (eg: user friendly description) whilst passing another (eg: key value) to the report. 这使您可以向最终用户显示一件事(例如:用户友好的描述),同时将另一件事(例如:键值)传递给报表。

In your dataset for the test parameter add a column to hold the Label of the value you want to pass through to the query. 在测试参数的数据集中,添加一列以保存要传递给查询的值的Label This can be the same as your Value if you so wish, but gives you the flexibility you require on the Null entry: 如果您愿意,可以与您的Value相同,但是可以为您在Null条目上提供所需的灵活性:

SELECT DISTINCT Corp_Test as Value
               ,Corp_Test as Label
  FROM [Tfs_Warehouse].[dbo].[CurrentWorkItemView]
 WHERE ProjectNodeGUID = @ProjectGuid
   AND System_WorkItemType = 'Marketing Feature'
UNION ALL           -- As you have DISTINCT above, UNION ALL will work faster and give the same results as UNION (which removes duplicates)
SELECT 'Null' as Value
      ,'No PSI' as Label
ORDER BY Corp_Test

Once you have done this, change your parameter to use the Value field as the parameter value and the Label field as the label shown to the user. 完成此操作后,更改参数以将“ Value字段用作参数值,将“ Label字段用作向用户显示的标签。

SELECT
ISNULL(Corp_Test,'No PSI') AS Corp_Test
FROM 
(SELECT DISTINCT Corp_Test
  FROM [Tfs_Warehouse].[dbo].[CurrentWorkItemView]
 WHERE ProjectNodeGUID = @ProjectGuid
   AND System_WorkItemType = 'Marketing Feature'
UNION
SELECT 'Null'
) AS Corp
ORDER BY ISNULL(Corp_Test,'No PSI') 

Remember to implement the change in your where clause main query. 记住要在where子句主查询中实现更改。 By main query, I mean the query that is feeding your report 所谓主查询,是指正在提供报告的查询

The simple and easiest way is what @sgeddes answered in his comment. @sgeddes在他的评论中回答了最简单,最简单的方法。

I just repleced the where COALESCE(Corp_Test, 'Null') IN (@TestParam) with where COALESCE(Corp_Test, 'No PSI') IN (@TestParam) , and in the dataset I replaced the SELECT 'Null' with SELECT 'No PSI' . 我只是repleced的where COALESCE(Corp_Test, 'Null') IN (@TestParam)where COALESCE(Corp_Test, 'No PSI') IN (@TestParam)并在数据集我更换了SELECT 'Null'SELECT 'No PSI'

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

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