asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Business Intelligence with Microsoft SQL Server Reporting Services - Part 2
By Adnan Masood
Rating: 3.9 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Table of Contents

    • Part 1
      • Introduction
      • Reporting Services Installation
      • Programming Reporting Services
      • Report Manager
    • Part 2
      • Parameterized Reports
      • Calling Stored Procedures from Reports
      • The Report Viewer Control
    • Part 3
      • Using Reporting Server Web Services
      • Using Custom Code in Reports
      • Subscription Scheduling in Reporting Server
      • Caching and Rendering Preference
      • Conclusion
      • References and Further Readings
      • About The Author
    • Download Sample Code

    Parameterized Reports

    Not all reports are static, most of the enterprise reports are data driven or parameterized. In the following section I'm adding two variables, startdate and enddate in the Orders Report. These arguments will be used to filter the data being queried from orders table.

    The parameters are regarded as query parameters and as you can see in the query window below, these parameters are passed in the SQL query string.

    Upon execution, the Report Designer preview asks for parameters values. When executing from a browser, it shows the parameters toolbar with default values in it. You can change the values in the parameters toolbar. Parameters can be set to null, defaulted through report manager and can also be data driven.

    Calling Stored Procedures from Reports

    If your enterprise reporting system policy dictates business logic to be encapsulated in stored procedures, reporting services are there to rescue you again. SQL server stored procedure provides an efficient way of processing compiled SQL statements and can be used by reporting services to build reports on top of their result set.

    In the following two examples, I'll be using stored procedures from northwind database and display their result in reports. The dataset creation process is similar to one specified above, however this time command type is selected as stored procedure.

    This first example is simpler; it uses the stored procedure "Ten Most Expensive Products" and use it as data source for its tabular data binding. The process of using stored procedure as data source can be seen below.


    Figure: Creating a data source from stored procedure via data tab in reporting services IDE for visual studio.NET

    This binding exposes collection of two fields (Ten Most Expensive Products, UnitPrice) which can be used as fields in the report table. After adding these fields in the recurring row, I've set the headings in header and we are all set to preview the report.


    Figure: Adding the fields in report table.

    Upon execution, the report will look like the following.


    Figure: Report preview which uses Ten Most Expensive Products as data source.

    Second example is a bit complex as it uses stored procedure as well as SQL to retrieve the parameters for combo box. The intent of this report is to provide sale by the category of products which includes beverages, produce, seafood, etc. Every product is associated with a category and the stored procedure "SalesByCategory" takes category as input and provide the sales breakdown of products in that category. However, to achieve this, we would need to display the list of categories in the report. Here is the step by step diagrammatic flow of how to achieve this goal.


    Figure: Creating a stored procedure based data set.

    First, as its name depicts the sales by category stored procedure provides the sales history on the basis of product category. To provide interactivity in the report, we need to acquire the data driven parameters i.e. list of categories from database. This can easily be achieved from report parameters window as shown in this figure below. The report is reading category name, order year and their corresponding values from database as parameters.


    Figure: Report Parameters being retrieved from database (step 1)


    Figure: Assigning default Report Parameters. (step 2)


    Figure: Assigning the corresponding value fields for report parameters. (step 3)

    Finally the report could be seen as follows. The Category name and order are drop down lists for selection and the report takes these parameters and pass them on the salesbycategory stored procedure for the required result set.


    Figure: Report preview; combo boxes for category details

    This whole procedure as demonstrated with GUI above can be represented in RDL as follows.

    <DataSources>
      <DataSource Name="Northwind">
        <rd:DataSourceID>1a755f4d-006e-42ce-804b-852dc13c6840</rd:DataSourceID>
        <ConnectionProperties>
          <DataProvider>SQL</DataProvider>
          <ConnectString>initial catalog=Northwind</ConnectString>
        </ConnectionProperties>
      </DataSource>
    </DataSources>
    

    Listing: The RDL segment for data source. Notice the data source id as guid to uniquely identify the data source

    <DataSets>
      <DataSet Name="Northwind">
        <Fields>
          <Field Name="ProductName">
            <DataField>ProductName</DataField>
            <rd:TypeName>System.String</rd:TypeName>
          </Field>
          <Field Name="TotalPurchase">
            <DataField>TotalPurchase</DataField>
            <rd:TypeName>System.Decimal</rd:TypeName>
          </Field>
        </Fields>
        <Query>
          <DataSourceName>Northwind</DataSourceName>
          <CommandType>StoredProcedure</CommandType>
          <CommandText>SalesByCategory</CommandText>
          <QueryParameters>
            <QueryParameter Name="@CategoryName">
              <Value>=Parameters!CategoryName.Value</Value>
            </QueryParameter>
            <QueryParameter Name="@OrdYear">
              <Value>=Parameters!OrdYear.Value</Value>
            </QueryParameter>
          </QueryParameters>
          <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
        </Query>
      </DataSet>
    

    Listing: The RDL segment for dataset. Query parameters are specified in this segment.

      <DataSet Name="Categories">
        <Fields>
          <Field Name="CategoryID">
            <DataField>CategoryID</DataField>
            <rd:TypeName>System.Int32</rd:TypeName>
          </Field>
          <Field Name="CategoryName">
            <DataField>CategoryName</DataField>
            <rd:TypeName>System.String</rd:TypeName>
          </Field>
          <Field Name="Description">
            <DataField>Description</DataField>
            <rd:TypeName>System.String</rd:TypeName>
          </Field>
          <Field Name="Picture">
            <DataField>Picture</DataField>
            <rd:TypeName>System.Byte[]</rd:TypeName>
          </Field>
        </Fields>
        <Query>
          <DataSourceName>Northwind</DataSourceName>
          <CommandText>SELECT * FROM CATEGORIES</CommandText>
          <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
        </Query>
      </DataSet>
    </DataSets>
    

    Listing: The RDL segment for retrieving parameters. It includes the Command text and field definitions.

    <ReportParameters>
      <ReportParameter Name="CategoryName">
        <DataType>String</DataType>
        <DefaultValue>
          <DataSetReference>
            <DataSetName>Categories</DataSetName>
            <ValueField>CategoryName</ValueField>
          </DataSetReference>
        </DefaultValue>
        <Prompt>CategoryName</Prompt>
        <ValidValues>
          <DataSetReference>
            <DataSetName>Categories</DataSetName>
            <ValueField>CategoryName</ValueField>
            <LabelField>CategoryName</LabelField>
          </DataSetReference>
        </ValidValues>
      </ReportParameter>
      <ReportParameter Name="OrdYear">
        <DataType>String</DataType>
        <DefaultValue>
          <Values>
            <Value>1998</Value>
          </Values>
        </DefaultValue>
        <Prompt>OrdYear</Prompt>
        <ValidValues>
          <ParameterValues>
            <ParameterValue>
              <Value>1996</Value>
            </ParameterValue>
            <ParameterValue>
              <Value>1997</Value>
            </ParameterValue>
            <ParameterValue>
              <Value>1998</Value>
            </ParameterValue>
          </ParameterValues>
        </ValidValues>
      </ReportParameter>
    </ReportParameters>
    

    Listing: The RDL segment for fixed Parameters. It specifies the label, data value data set reference along with parameter (Ordyear) values and default values.

    Reporting services opens up a wide arena for you for data binding. The above examples demonstrate how can we use stored procedures in reports; however its your choice to use dynamic SQL, business objects (custom assemblies), stored procedures or any other custom data source for your report.

    The Report Viewer Control

    The report viewer control is an excellent intrinsic tool provided to facilitate report viewing in hosted client web or desktop application. This control makes URL based access a breeze and reporting integration to any existing .NET app a charm. This control comes with code both in VB.NET and C#. This control is available %System Root%\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\Samples\Applications\ReportViewer\vb. You may want to build the solution to incorporate the assembly in your web / desktop application project.

    In rest of this section, I'll demonstrate how you can use this control to create a sample web application which supports reporting via URL access. The source code of this project is available as ParametricReporting.csproj in the source code zip file. First of all, in order to add this control in your web application, go to tools -> Add/Remove Toolbox Items. In the Customize Toolbar dialog box click the .NET Framework Components tab, browse to the location specified above and select ReportViewer.dll. Report Viewer component would be added to VS.NET toolbox and you can add it into your web form. This step is shown in the figure below.


    Figure: Adding the report viewer control in the web form.

    This is a simple web application which uses two calendar controls to select starting and ending date for orders report. The purpose of this example is to demonstrate how easily reports can be embedded in a web application. It also shows that reporting services functionality can easily be extended by traditional applications and their controls.


    Figure: Report viewer control added in web form. VS.NET IDE

    With couple of lines of code to pass the orders details parameters to the Report viewer control, the following report can be achieved.


    Figure: Report rendered by using report viewer control.

    With just modifying the rendering format to PDF, I can get the report in PDF within the report viewer control. This makes it a very handy choice for showing supporting reports and business intelligence associations within interactive web and desktop applications.


    Figure: Report rendered as PDF by using the URL access and report viewer control.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Aug 31, 2005 - The X-Factor in SOA
    In this article, Joseph Poozhikunnel examines the importance of the three X's -- namely XML, XML Schema, and XSLT -- in a service oriented architecture (SOA). He then defines the design considerations that need to be adopted when designing a system based on SOA and examines the pitfalls that can arise if they're not followed.
    [Read This Article]  [Top]
    May 19, 2005 - Building an Enterprise Service Bus to Support Service Oriented Architecture
    In this article, Joseph Poozhikunnel defines an Enterprise Service Bus (ESB) that can be created to support any Service Oriented Architecture (SOA) adopted by an organization. The type of ESB required could vary as there is no "one size fits all", therefore the article examines a few of the mechanisms available that could be adopted to implement an ESB.
    [Read This Article]  [Top]
    Apr 14, 2005 - Building an End User Defined Data Model - Part 2
    In the seconmd part of his series on building an end user defined data model, Peter Scheffler gets into the actual meat of the model and discusses real-world implementation details and the actual table layouts.
    [Read This Article]  [Top]
    Mar 24, 2005 - Building an End User Defined Data Model - Part 1
    In the first article in this series, Peter Scheffler introduces the concept of a rules-based database engine that allows clients to make changes to their database structure without breaking the applications that access the database.
    [Read This Article]  [Top]
    Jan 19, 2005 - Developing a Simple Service Oriented Architecture
    The basic premise of a Service Oriented Architecture (SOA) system is to decouple applications from each other in order to make them autonomous. In this article, Joseph Poozhikunnel presents a simple SOA framework that can be used as a starting point for a system that addresses your specific business needs.
    [Read This Article]  [Top]
    Nov 3, 2004 - 10 Steps to a Successful Versioning and Deployment Strategy for .NET
    A well rounded versioning and deployment strategy considers several overlapping and interdependent .NET Framework concepts. In this article, Michele Leroux Bustamante will take you through a ten step program that reviews these core concepts, their relationship, and provides guidance for successful application deployments for the .NET Framework.
    [Read This Article]  [Top]
    Oct 13, 2004 - Business Intelligence with Microsoft SQL Server Reporting Services - Part 1
    Adnan Masood discusses Microsoft's comprehensive integrated business intelligence, data mining, analysis and reporting solution: Microsoft SQL Server Analysis services and Microsoft SQL Server Reporting services.
    [Read This Article]  [Top]
    Dec 15, 2003 - Realizing a Service-Oriented Architecture with .NET
    Chip Irek examines the architectural issues and component design issues of building a .NET application in a service-oriented architecture.
    [Read This Article]  [Top]
    Oct 21, 2003 - Achieving Reuse in ASP .NET - Part 1: Barriers to Reuse
    The importance of reuse can't be overstated, especially in light of the degree to which we go out of our way to avoid it, but implementing a reuse strategy means creating high-quality low-cost applications that just might save your job.
    [Read This Article]  [Top]
    Jun 16, 2003 - The .NET Architect: Enterprise Template Dynamic Help
    One of the most critical components of any application is the help file collection. The fourth article in Brian Korzeniowski's Enterprise Template series examines Dynamic Help in Visual Studio .NET and focuses on the logical process of creating help content.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers