SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ssrs 2008 r2, select none, one or more values


ssrs 2008 r2, select none, one or more values

Author
Message
wendy elizabeth
wendy elizabeth
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3764 Visits: 824
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?
Jack Corbett
  Jack Corbett
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45347 Visits: 14925
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
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

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
wendy elizabeth
wendy elizabeth
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3764 Visits: 824
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?
Jack Corbett
  Jack Corbett
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45347 Visits: 14925
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
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search