?
Solved

How do I select the result value of a case expression

Posted on 2010-11-22
4
Medium Priority
?
549 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

741 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