Solved

How do I select the result value of a case expression

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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 …
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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

815 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

9 Experts available now in Live!

Get 1:1 Help Now