I have an SSRS report that filters the Items based on whether its an Type I (Item) or A (Accessories). 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
(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. IF 'E' then all from the category parameter which is also a multi select but not include Category A.
You cannot just have a case
statement by itself as listed in OP. You can however apply a SQL filter conditionally by using a pattern such as this:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.