Home > Repair Count By Type Report
Book Excerpt:
EMAIL THIS

Repair Count By Type Report

27 Feb 2006 | SearchSQLServer.com

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   

Microsoft SQL Server 2005: The Complete Reference The following excerpt, courtesy of McGraw-Hill Osborne Media, is from Chapter 5 of the book Microsoft SQL Server 2005 Reporting Services 2005 written by Brian Larson. Click here to purchase the book.



Repair Count By Type Report

Now let's move down the road a little further and create a matrix report without the wizard.

The Repair Count By Type Report Features Highlighted

  • Creating a matrix report from scratch
  • Using a specialized property dialog box

Business Need

GDS needs to purchase several new transports to update their delivery fleet. The company must decide which type of transport to purchase. One factor in the decision is the amount of time the new transports will spend in the maintenance hanger for repairs and preventative maintenance.

Upper management has asked the GDS maintenance department to provide a report showing the number of each type of repair required by each type of transport. The report should include statistics from all transports, both active and retired. Also, the report should group the repairs by their cause.

Task Overview

  1. Reopen the Chapter05 Project, Create a New Report in the Chapter05 Project, Select the Shared Data Source, and Create a Dataset
  2. Place a Matrix Item on the Report and Populate It
  3. Add Column Grouping and Other Report Formatting

Repair Count By Type Report, Task 1: Reopen the Chapter05 Project, Create a New Report in the Chapter05 Project, Select the Shared Data Source, and Create a Dataset

  1. If you closed the Chapter05 project, reopen it.
  2. In the Solution Explorer on the right side of the screen, right-click the Reports folder.
  3. Put your mouse pointer over Add in the Context menu and wait for the submenu to appear. Select New Item from the Context menu. This displays the Add New Item Chapter05 dialog box.
  4. Make sure the Report icon is selected in the Templates area. Enter RepairCountByType for the name.
  5. Click Add. A new report called RepairCountByType.rdl is created in the Chapter05 project. You are taken to the Data tab of this new report.
  6. Select from the Dataset drop-down list. The Dataset dialog box appears.
  7. Enter RepairsByType for the name in the Dataset dialog box.
  8. Galactic (shared) is selected for the data source by default. Click OK. You return to the Data tab, which now displays the Generic Query Designer.
  9. Click the Generic Query Designer button to switch to the Graphical Query Designer.
  10. Right-click in the diagram pane of the Graphical Query Designer screen. Select Add Table from the Context menu.
  11. Add the following tables to the query:
    Repair (dbo)
    Transport (dbo)
    TransportType (dbo)
    RepairWorkDoneLink (dbo)
    WorkDone (dbo)
    RepairCause (dbo)
    
  12. Click Close to exit the Add Table dialog box.
  13. Check the following column in the Repair table:
    RepairID
    
  14. Check the following column in the TransportType table:
    Description
    
  15. In the criteria pane, type TypeOfTransport in the Alias column in the Description row.
  16. Check the following column in the WorkDone table:
    Descrip
  17. tion
  18. In the criteria pane, type TypeOfWork in the Alias column in the Description row for the WorkDone table.
  19. Check the following column in the RepairCause table:
    Description
    
  20. In the criteria pane, type RepairCause in the Alias column in the Description row for the RepairCause table.
  21. Type 1 in the Sort Order column for RepairCause. Type 2 in the Sort Order column for TypeOfWork
  22. .
  23. Right-click in the SQL pane and select Execute SQL from the Context menu. The Graphical Query Designer should appear similar to this:


Figure 21

Task Notes Although this report is a pretty straightforward request, we need to link together a number of tables to collect the necessary data. What we are interested in is repairs, so we start with the Repair table. However, none of the fields we need in the result set are in the Repair table. To find the type of transport being repaired, we need to join the Transport table with the Repair table, and then join the TransportType table to the Transport table. To find the type of work done, we need to join the RepairWorkDoneLink table to the Repair table, and then join the WorkDone table to the RepairWorkDoneLink table. Finally, to group by the cause of the repair, we need to join the RepairCause table to the Repair table. If you get confused by all of this, refer to Figure 3-23 in Chapter 3.

Repair Count By Type Report, Task 2:

Place a Matrix Item on the Report and Populate It

  1. Click the Layout tab to begin working on the report layout.
  2. Click the Matrix report item in the Toolbox. The mouse pointer changes to a matrix icon and crosshairs when you move your mouse pointer over the report layout area.
  3. Click-and-drag the mouse over the lower three-quarters of the report layout.
  4. When you release the mouse button, after dragging, a matrix is created to occupy the area you just defined. By default, every cell in the matrix is occupied by an empty text box.
  5. In the Datasets window, expand the RepairsByType dataset. Drag the TypeOfTransport field from the Datasets window and drop it on the cell containing the word "Columns." The values in this column in the dataset determine the columns in the matrix report.
  6. Drag the TypeOfWork field from the Datasets window and drop it on the cell containing the word "Rows." The values in this column in the dataset determine the rows in the matrix report.
  7. Drag the RepairID field from the Datasets window and drop it on the cell containing the word "Data."
  8. In the cell where you just dropped the RepairID field, change Sum to Count, so the contents of the cell appear as follows:
    =Count(Fields!RepairID.Value)
    
  9. With this cell still selected, change the following property:

    PropertyNew Value
    TextAlignCenter

  10. Reduce the width and height of the columns in the matrix. When you finish, your report design should look similar to this:

  11. Figure 22

  12. Click the Preview tab. Your report should look similar to the following illustration. The rows and columns in your report may appear in a different order from those shown here.


Figure 23

Task Notes Because the matrix report always groups a number of records from the dataset to create the entries in the matrix, the field that supplies the data for the matrix must be enclosed in some type of aggregate function. If the field placed in the data cell is a number, Report Designer encloses the field in the SUM() aggregate function.

The RepairID field, which we placed in the data cell in Step 7, is a number. However, it does not make sense to add up the RepairIDs. Instead, we want to count the number of RepairIDs. For this reason, we changed the SUM() aggregate function to the COUNT() aggregate function.

Repair Count By Type Report, Task 3:
Add Column Grouping and Other Report Formatting

  1. Click the Layout tab to return to the report layout.
  2. Click the cell in the upper-right corner of the matrix and change the following properties:

    PropertyNew Value
    FontWeightBold
    TextDecorationUnderline

  3. Click the square in the upper-left corner of the gray border to select the matrix item.
  4. In the Properties window, click the Property Pages button shown in the following illustration. The Matrix Properties dialog box appears.

  5. Figure 24

  6. Click the Groups tab.
  7. In the Rows area, click Add. The Grouping and Sorting Properties dialog box appears.
  8. Next you set up your matrix for drilldown. Replace matrix1_RowGroup2 with matrix1_RepairCause for the name. Select Fields!RepairCause.Value from the drop-down list in the first row under Expression. Click OK.
  9. In the Rows area, click Up to move matrix1_RepairCause to the top of the list. Click the matrix1_TypeOfWork entry. Click Edit in the Rows area. The Grouping and Sorting Properties dialog box appears.
  10. Click the Visibility tab. Set the Initial Visibility to Hidden. Click the Visibility Can Be Toggled by Another Report Item check box. Select textbox2 from the Report Item drop-down list. (If textbox2 is not in the drop-down list, type textbox2 for the Report item value.)
  11. Click OK in the Grouping and Sorting Properties dialog box. Click OK in the Matrix Properties dialog box.
  12. Click the cell in the upper-left corner of the matrix and change the following properties:

    PropertyNew Value
    FontWeightBold
    TextDecorationUnderline
    ValueCause/Type of Repair Work

  13. Click the Textbox report item in the Toolbox. Click-and-drag the mouse over the area above the matrix on the report layout area. When you release the mouse button, after dragging, a text box is created to occupy the area you just defined. Click the text box and type the following:
    Repair Count By Type Report
  14. With the text box still selected, make the following changes in the Properties window:

    PropertyNew Value
    FontSizeBold
    TextDecoration16pt
    FontWeightBold
    TextAlignCenter

  15. Your report layout should appear similar to the illustration.

  16. Figure 25

  17. Click the Preview tab. The report should appear as follows.

  18. NOTE

    If the report displays an error message mentioning textbox2 when you preview the report, then textbox2 was not the name assigned to the text box containing the RepairCause group label. Return to the Layout tab and select the text box containing the =Fields!RepairCause.Value expression. Look at the Name property in the Properties window. Return to the drop-down list you populated in Step 9 of this task and replace textbox2 with this name. Click OK to exit the dialog boxes and preview the report again.



    Figure 26

  19. Click Save All in the toolbar.

Task Notes The Property Pages button in the Properties window provides an alternative way to change the properties of a report item. This button displays a dialog box that deals specifically with the properties of the selected report item. These specialized property dialog boxes can make it much easier to modify the properties of a report item. You can also access the specialized property dialog boxes by right-clicking a report item and selecting Properties from the Context menu.

Click for the next excerpt in this series: Transport Information Sheet Task 1 and 2: Create New Report and Dataset

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Microsoft SQL Server 2005
End of life comes for SQL Server 2005 SP2, 2008
SQL Server Reporting Services Fast Guide
SQL Server Service Broker Tutorial and Reference Guide
Tips for tuning SQL Server 2005 to improve reporting performance
SQL Server consolidation: Why it's an optimization technique
Parent-child dimensions in SQL Server 2005 with Analysis Services MDX
Enforcing data integrity in a SQL Server database
SSIS error message due to installation problem on SQL Server 2005
Should you upgrade to SQL Server 2005 or SQL Server 2008?
Basics for working with DATETIME and SMALLDATETIME in SQL Server 2005
Microsoft SQL Server 2005 Research

SQL Server Business Intelligence (BI) and Data Warehousing
Programming report generation with SQL Server Reporting Services 2008
Using the Pivot transformation in SQL Server Integration Services
DBA career paths could lead to business intelligence
Are data warehouses made for the cloud?
Q&A: Business intelligence gets a facelift in SQL Server 2008 R2
Project Gemini gets a new name, Madison earns buzz
Speed up reports in SQL Server Reporting Services with caching
Data Transformation Services vs. SSIS: The key differences
Using package configurations in SQL Server Integration Services (SSIS)
How SQL Server 2008 components impact SharePoint implementations

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
application server  (SearchSQLServer.com)
Yukon  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary




Secure SQL - Data Security for Your Database
HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts