SSRS多值可选

时间:2018-03-19 16:54:12

标签: reporting-services parameters multivalue

我遇到了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;

1 个答案:

答案 0 :(得分:1)

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

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)