Solved

How do I select the result value of a case expression

Posted on 2010-11-22
4
505 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
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:joevi
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Great, thanks!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now