Solved

How do I select the result value of a case expression

Posted on 2010-11-22
4
541 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Introduction In the following article I’ll be discussing and demonstrating several different ways of how images can be put on a report. I’m using SQL Server Reporting Services 2008 R2 CTP, more precisely version 10.50.1352.12, but the methods ex…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

729 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