[英]Parameter to filter in the where clause SSRS
I have an SSRS report that filters the Items based on whether its an Type I (Item) or A (Accessories). 我有一个SSRS报告,可根据其类型I(项)还是A(附件)来过滤项。 Currently this is multi select parameter where I have specified the values. 目前,这是我已指定值的多选参数。 But I would like to change this to a single select-able value with the following values: 但我想将其更改为具有以下值的单个可选值:
Is it possible to have case condition statements within the where clause like the following: 在where子句中是否可能有条件条件语句,如下所示:
WHERE
(CASE WHEN @Pram1 IN ('A') THEN ('I,'A')
WHEN @Pram1 IN ('I') THEN ('I')
WHEN @Pram1 IN ('E') THEN ('I')
ELSE
-1 END)
THEN based on this I will have the conditions for the Categories. 然后基于此,我将具有类别的条件。 IF its 'A' then it will include all categories. 如果其为“ A”,则它将包括所有类别。 IF 'E' then all from the category parameter which is also a multi select but not include Category A. 如果是'E',则全部来自category参数,这也是一个多选,但不包括CategoryA。
You cannot just have a case
statement by itself as listed in OP. 您不能仅拥有OP中列出的case
说明。 You can however apply a SQL filter conditionally by using a pattern such as this: 但是,您可以使用以下模式有条件地应用SQL筛选器:
SELECT *
FROM yourProductsTable p
WHERE
--Apply the "type" filters
(
(
@TypeParam = 'All' --then include both Items and Accessories
AND p.ProductType in ('I','A')
)
OR
(
@TypeParam = 'A' --Accessories only
AND p.ProductType = 'A'
)
OR
(
@TypeParam = 'I' --Items only
AND p.ProductType = 'I'
)
OR
(
@TypeParam = 'E' --Items only, but Exclude Category A and Product D
AND p.ProductType = 'I'
AND p.Category <> 'A'
AND p.Product <> 'D'
)
)
--Apply Other filters: i.e. category
AND p.Category in (@SSRSCategoryMultiSelectParam)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.