It is important to consider to filter report data based on user’s selection criteria as many databases contain large amounts of data. This post discusses different techniques to filter report data using report parameter concepts. By using the filters on reports, it greatly reduces the network traffic and helps the report to render efficiently.
We are using same data source and query that we used to demonstrate the tabular reports demo. You can read the post here.
Filtering by query - You can filter the records in query by adding a where clause to it. Write the following query in query designer as follows
Defining parameters – There are two different types of parameters which you can use in report design.
- Data Set Parameters- can be defined using database objects like stored procedures and user defined functions.
- Report Parameters – are defined from ad hoc query or SQL stored procedure, but you don’t have to parameterize the queries to use parameters in a report unlike in Data Set Parameters.
The following query contains two parameters used to specify the range of date values for filtering a Date type field
You can set the data type for the parameters that defined above as shown below
Run the report to see the result , you can notice a date picker control appears in report to select the date value.
Creating a list of parameters – It would be nice if you could provide user a list of values as parameter for selection. You can create this list using either Parameter properties dialogue box or use a query to return a list of available values.
To create a query-driven list, create a data set called Years under the same data source. Enter the following SQL statement as shown in the dialogue box
To set up the parameter list , right click on the Year Parameter and select the Get values from a Report parameter properties dialogue box and select the Years from dataset dropdown and select the CalendarYear from value field list.
Configuring Multi-Value Parameters – You can configure parameters for users to select a multiple values. Modify the year by right clicking on parameter properties. Check Allow multiple values in the Report Parameter Properties dialogue and click ok.
run the query, you should be able to see the results as shown below
More about SQL Server 2008 Report parameters can be read here
|Share this post :|