SSRS多值可选

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSRS多值可选相关的知识,希望对你有一定的参考价值。

我在SSRS和多选值方面遇到了一些问题。基本上,除了Date参数(@From)和(@To)之外的所有其他参数,我想要是可选的。允许从查询中提取多个值,但如果用户不想指定值,则我希望它提取所有项目。

因此,例如,如果Ward参数未指定值,则它包括所有值。

有任何想法吗?

SELECT
 rTranslog.[Month]
 ,CONVERT(datetime,rTranslog.LogDateTime, 103) AS [Date]
 ,rTranslog.IssueDate
 ,rTranslog.Site
 ,rTranslog.CaseNo
 ,rTranslog.NSVCode
 ,REPLACE(rProduct.LabelDescription, '!', ' ') AS [Drug] 
 rProduct.ReportGroup
,rTranslog.BNFCode
,rTranslog.Ward
,rConsultant.ConsultantName
,rSpecialty.Description AS [SpecialtyName]
,rTranslog.Kind
,rTranslog.LabelType
,rTranslog.Qty AS [Quantity]
,rTranslog.CostExTax/100 AS [CostGBPExVat]
,rTranslog.Cost/100 AS [CostGBPIncVAT]
,rTranslog.DispId

FROM
 rTranslog
  INNER JOIN rProduct
   ON rTranslog.NSVCode = rProduct.NSVCode
  LEFT JOIN rConsultant
   ON rConsultant.Consultant = rTranslog.Consultant
  LEFT JOIN rSpecialty
   ON rTranslog.Specialty = rSpecialty.SpecialtyCode

WHERE rTranslog.IssueDate BETWEEN (@To) AND (@From) 
  AND rTranslog.Ward IN (@Ward) OR (@Ward) Is Null  
  AND rProduct.LabelDescription IN (@Drug) OR (@Drug) Is Null
  AND rTranslog.CaseNo IN(@CaseNo) OR (@CaseNo) Is Null
  AND rSpecialty.Description IN(@Specialty) OR (@Specialty) Is Null
  AND rTranslog.Site IN (@Site)

ORDER BY [Date] ASC;
答案

你几乎就在那里,只是稍微改变应该给你你想要的东西。

WHERE rTranslog.IssueDate BETWEEN (@To) AND (@From) 
  AND (rTranslog.Ward IN (@Ward) OR @Ward Is Null)
  AND (rProduct.LabelDescription IN (@Drug) OR @Drug Is Null)
  AND (rTranslog.CaseNo IN(@CaseNo) OR @CaseNo Is Null)
  AND (rSpecialty.Description IN(@Specialty) OR @Specialty Is Null)
  AND rTranslog.Site IN (@Site)

以上是关于SSRS多值可选的主要内容,如果未能解决你的问题,请参考以下文章

可选的SSRS参数

Option可选值可选值

s-s-rS 中的可选多值参数

具有多值参数的存储过程表现奇怪

Power BI分页报表连接Power BI Dataset及多值参数设置

csharp 从代码调用SSRS报告并获取文件