Solved

How do I select the result value of a case expression

Posted on 2010-11-22
4
535 Views
Last Modified: 2012-08-13
Hello,

This is for an SSRS report and I'm not sure if what I'm trying to accomplish should be done in the SQL Query itself or somewhere in my Reporting Services report.

I have two separate agencies: ABC and DEF. Each agency has a bunch of sub-agencies defined my state. So in my database I would have:

ABC - NY
ABC - TX
ABC - MA
DEF - NY
DEF - PA
etc.

Transactions are coded to the individual agencies as displayed above. But my end users want the option to select either ABC or DEF or both (Select All). On the selection parameter they do not want to see it broken out to the sub-agencies. I have tried accomplishing this by setting up a second dataset and using select distinct with a case expression, but it returned no data when I ran my report.

Does anyone know how to do what I'm trying to accomplish?

Thanks!
0
Comment
Question by:erp1022
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:joevi
ID: 34189087
Ideally you'd feed the parameter (@Agency) with a query (including an 'All' value). Use the query to feed a parameter listboxe in RS then create a dataset with some If..then logic (for the 'All' conditon). The rest is pretty much straight up TSQL.
0
 

Author Comment

by:erp1022
ID: 34190618
More specific please. Not sure what a parameter listbox is or how to set one up. Not sure what the if...then logic should be or how to set that up. And 'the rest is pretty much straight up TSQL' - the rest of what? What needs to be done in SQL?
0
 
LVL 4

Accepted Solution

by:
joevi earned 500 total points
ID: 34191254
Lets call your table 'Agencies' with Agency and SubAgency columns..
In BIDS:
1) Set up a Datasource pointing to the Agencies table.
2) Create Dataset1 using this query:
Select 'All' as Agency, 1 as SortOrder
UNION
Select Distinct Agency , 2 as SortOrder from Agencies
Order by SortOrder, Agency
3) Create a Parameter (lets call it @Agency) using the following properties:
Available Values-Get Values From Query, Datatset:Dataset1, Value Field:Agency, Label Field:Agency
4) Create Dataset2. I'd suggest passing the @Agency value to a stored procedure but for illustration purposes just paste the following into the Dataset2 Query
IF @Agency = 'All'
BEGIN
SELECT Agency, SubAgency FROM Agencies
END
ELSE
BEGIN
SELECT Agency, SubAgency FROM Agencies WHERE Agency = @Agency
END

Note: BIDS will complain about the query but for demo purposes it'll work.

5) Create a report table, add the appropriate columns and you should be good to go.
0
 

Author Comment

by:erp1022
ID: 34192454
Great, thanks!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question