ssrs 2008 r2, select none, one or more values

  • In an an existing SSRS 2008 r2 report, I want to have a parameter called @hair where the user 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. This is due to

    the inventory table contains columns like hairproduct, eyeproduct, faceproduct. If a

    particular product is purchased, the column will contain a value. If a customer purchases all 4 hair products and 3 eyeproducts, and 9 faceproducts, the inventory table will contain 16 columns for a particualr customer.

    In the parameter window, I can use the following to have the correct values be displayed in the selection window:

    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

    **Note the @hairproduct parameter allows blank values and allows multiple values.

    However in the main query for the ssrs 2008 r2 report, I am not certain how I would change the following statement to select 'No hair product purchased'.

    The current select statement looks like the following:

    select customer_id,hairproduct

    from inventory where customer_id = @customerid

    hairproduct in (@hairproduct).

    Basically I need to change the main query, dataset that matches the parameter @hairproduct, or possibly add a new parameter that means 'No hair product purchased' to report on the customer that has one or more hair products purchased or none.

    Thus can you tell me and/or show me sql that will solve my problem?

  • In my opinion, the best way to solve this would be by using an expression in the query for your main dataset that evaluates the selection in the hair product parameter. Something like this:

    ="select customer_id,hairproduct

    from inventory where customer_id = @customerid" & IIF(Parameters!hairProduct.value = "", "", " and hairproduct in (@hairproduct);"

    I may have something wrong in that expression because it has been awhile since I've used an expression in a dataset query as I usually use stored procedures for my report datasets, but I think that should give you a basic idea of what needs to be done.

    Edit: replaced single quoted in expression with double-quotes.

  • can you explain what you mean by "IIF(Parameters!hairProduct.value = "", "", " and hairproduct in (@hairproduct);"

    How does this solve the question when there are no hairProducts and when there is 1 or more hair products?

  • The IIF is an inline IF statement so the expression I provided says, if the value for the parameter is empty then don't bother adding that parameter to the query being passed to SQL server, but if it is not pass the value of the parameter to the SQL Server.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply