Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

ssrs 2008 r2, select none, one or more values Expand / Collapse
Author
Message
Posted Wednesday, February 26, 2014 4:09 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 4:11 PM
Points: 366, Visits: 428
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?
Post #1545632
Posted Wednesday, February 26, 2014 8:18 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 12:31 PM
Points: 11,265, Visits: 13,027
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.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #1545673
Posted Wednesday, February 26, 2014 9:11 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 4:11 PM
Points: 366, Visits: 428
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?
Post #1545686
Posted Thursday, February 27, 2014 12:44 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 12:31 PM
Points: 11,265, Visits: 13,027
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.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #1546084
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse