ssrs 2008 r2,选择1个或更多值或以上都不是

时间:2014-02-26 23:01:29

标签: sql-server tsql reporting-services ssrs-2008

在现有的SSRS 2008 r2报告中,我想要一个名为@hair的参数,其中用户

can see if the customer purchased one of the following items:
 1. hair spray,
 2. hair shampoo,
 3. Hair color,
 4. hair conditioner, or
 5. No hair product purchased.

The table is called inventory and the values for the field called hairproduct are
 1. hair spray = 'HR',
 2. hair shampoo = 'HS',
 3. hair color = 'HC',
 4. Hair conditionier = 'HD',
 5. If hair product is not purchased hairproduct value is null. 

这是由于     库存表包含hairproduct,eyeproduct,faceproduct等列。如果一个     购买特定产品时,该列将包含一个值。如果客户购买     所有4种发制品和3种眼影产品,以及9种面部产品,库存表将包含     16个列为特定客户。

在参数窗口中,我可以使用以下内容在中显示正确的值 选择窗口:

SELECT DISTINCT IsNull(inventory.hairproduct,'') as hairid,
CASE IsNull(inventory.hairproduct,'')
WHEN 'HR' then 'hair spray'
WHEN 'HS' then 'hair shampoo'
WHEN 'HC' then 'Hair color'
WHEN 'HC' then 'hair conditioner'
WHEN '' then 'No hair product purchased'
FROM Inventory

**请注意@hairproduct参数允许空值并允许多个值。

然而,在ssrs 2008 r2报告的主要查询中,我不确定如何更改以下内容 声明选择“没有购买头发产品”。

当前的select语句如下所示:

select customer_id,hairproduct
from inventory where customer_id = @customerid 
hairproduct in (@hairproduct)

基本上我需要更改主参数,与参数@hairproduct匹配的数据集,或者可能添加 一个新的参数,意思是“没有购买头发产品”来报告有一个或多个头发产品的客户 购买或没有。

因此,您能告诉我和/或向我展示可以解决我问题的SQL吗?

1 个答案:

答案 0 :(得分:0)

这应该这样做:

select
    customer_id,
    isnull(hairproduct,'No hair product purchased') as hairproduct
from inventory
where
    customer_id = @customerid 
    and isnull(hairproduct,'No hair product purchased') in (@hairproduct)