Tuesday, September 23, 2008

Dynamic Columns at Run time in SSRS Reports

Dynamic Columns at Run time in SSRS Reports
Here I am going to display the columns I have selected in the parameter in SSRS reports. Here is the procedure,
1.Open BI Studio
2.Select File--New--Project
3.Select Business Intelligence Projects as in Project Type
4.Select Report Server Project in Template
5.Give one Project Name and Click OK
6.The open you Solution Explorer--Right Click on the Share Data Sources-- Select Add --New Item-- Select Data Sources --Give Data Sources Name and Click ADD-- Set your Connection String and Click OK
7.Then--Right Click on the Reports--Select Add --New Item--Select Report--Give Report Name and Click ADD
8.Now the Design Window will open-- Select Data Tab
9.Click on the Dataset Drop Down Box -- Select New Data Set --Give Data Set Name--Select Data Source --Select Command Type--Write your query to get the Column Names of a Particular Table in the Query String Box and Click OK
10.To get the Column Names of a Particular Table use the following Query
Select COLUMN_NAME from INFORMATION_SCHEMA.Columns where Table_Name='DimBranch'
11.Then Click--Report--Report Parameter--Create one Parameter with Multi Value option--Pass the Column names you got from the above query to this parameter
12.Create another dataset with the following query
Select * from DimBranch
Note: This is your Main Data Set with this only you are going to generate SSRS report. So the Column name you got from the parameter should present in the main dataset while running this Main Dataset
13.Now Click Layout Tab in the Design Window
14.Click Tool Box -- Select Table--Drag Table Tool and Drop it into your Design Window
15.Then set the values for each column from Main Data Set
Now if you want to hide a particular Column at run time
16.Select the entire column and go to properties and select VisibilityàHidden
17.Then write the following expression in Hidden Property
=iif(Join(Parameters!ParameterName.Value,",").Contains("ColumnName"),false,true)
Here instead of Parameter Name give you parameter name and instead of ColumnName give you column name you want to hide
Note: You can hide any number of columns at run time but you have to write the above expression for each column. Those columns didn’t have the above expression will come default. If you write the above expression for a particular column then you have to select the Column Name in the Parameter to View in you report otherwise it will not be displayed in your report.
18.Then click Preview Tab in the Design WindowàSelect the Column Name à Click View Report
19.Now you can see the columns you selected in the Parameter

No comments: