DATABASE

Microsoft SQL Server 2005 : Report Definition and Design (part 4)

1/8/2011 3:51:45 PM
Expression Editor

The Expression Editor can create formulas for data display and formatting options. Most of the properties available for report objects have an <Expression...> option in the drop-down list. The Edit Expression dialog box has a color-coded syntax editor with Undo and Paste buttons. It also supports IntelliSense, so functions display parameter options as you type.

The Treeview control on the left has a list of syntax categories. Select one of these to fill the center list of syntax options. The description on the right panel explains how to use each feature. Double-click the item in the center panel to have it pasted into the expression. This approach is very useful for dataset fields and report parameters. The Constants category is specific to the property being edited and will show numbers, colors, or other appropriate values.

The example expression in Figure 19 sets the text color based on the value of two other fields.

Figure 19. Expression Editor with a simple formatting statement


Code and Custom Assemblies

The Expression Editor can reference .NET code that is stored with the report definition or in a custom assembly installed on the developer machine and report server. Use the Report Properties dialog box to find the Code and References tabs.

The Code page presents a simple text editor where you can add multiple instance-based methods written in Visual Basic. There is no color coding or IntelliSense. Consider writing the methods in a regular Visual Basic project and pasting the code into this window. To access the code in an expression, use the Code class as follows:

=Code.MyConvert(Fields!Price.Value)

You can write custom assemblies in any .NET language that uses static or instance methods. The calling syntax is different with a static member:

=MyNameSpace.MyClass.MyStaticMethod(Fields!Price.Value)

Make sure the assembly is loaded to the Reporting Services bin folder or the global assembly cache (GAC). Note that custom assemblies are loaded once for each development session and changes do not appear until Visual Studio is restarted.

Interactivity

The Reporting Service delivers static and interactive reports. Much of the interactivity comes from the use of query and report parameters. These values are known only by the end user running the report. Parameters can also be supplied from a table when you run subscriptions (as described later in this chapter).

Parameters and Filters

Most parameters are based on data source query input values. The exact syntax needed to create a parameter depends on the data source type. In SQL Server, the parameters start with the @ symbol.

The Chap21 solution has a report sample called Parameter.rdl that includes several query parameters. In this case, three datasets are created. The Category query lists all possible categories. The SubCategory dataset has a Filter expression that asks for the CategoryID. When you run this query on the Data tab, you are prompted for a CategoryID value. The third dataset is Product, which also has a filter asking for a SubCategoryID.

When this report is run on the Preview tab, a drop-down list is created for each parameter. You must specify a category before the dependent SubCategory list is enabled and filled. These parameters dynamically build on each other through expressions (as shown in Figure 20).

Figure 20. Dynamic parameters selected in the preview pane


On the Layout tab, use the Report menu or right-click on the design surface to show the Report Parameters menu option (Figure 21).

Figure 21. Report parameters generated automatically from query parameters


Notice that each dataset with a parameter creates a matching Report parameter. For each parameter, you can specify the name, data type, and prompt. If you need to associate data values with a parameter, these can be hardcoded or derived from a query. Default values can also be defined in this dialog box. The extra datasets in this report are used to fill the report parameter from a query. The order of the parameters is important because, in this example, a CategoryID is required before a SubCategory can be selected.

This is just one example of adding interactivity to a report. Parameters have many purposes in advanced report building. They can appear in titles, headers, expressions, and other calculations. Reports with parameters can be linked to each other to create sophisticated drill-down reporting.

Document Maps

Another interesting interactive feature is the document map, which you can see on the left side of the rendered DocumentMap.rdl report sample (Figure 22).

Figure 22. Document Map with a selected link in the preview pane


Each control has a Navigation tab in the property pages. Setting the Document Map entry to a field or expression causes the map to be displayed. Set the document map to a different grouping level to get the nested look in the sample. Document maps render in HTML, XLS (as a cover worksheet), and PDFs (as a document map).

Other  
  •  The SQL Programming Language : Creating Tables and Entering Data
  •  The SQL Programming Language : Complex Queries and Join Queries (part 4)
  •  The SQL Programming Language : Complex Queries and Join Queries (part 3)
  •  The SQL Programming Language : Complex Queries and Join Queries (part 2)
  •  The SQL Programming Language : Complex Queries and Join Queries (part 1)
  •  SQL Server 2008 : Implementing Objects - Viewing and Modifying Data
  •  SQL Server 2008 : Implementing Objects - Understanding DDL and DML Language Elements
  •  SQL Server : Reporting Services - Report Access and Delivery
  •  SQL Server : Reporting Services - Report Server Architecture
  •  SQL Programming Language : Ordering, Calculating, and Grouping in Queries
  •  Automating Blind SQL Injection Exploitation
  •  Blind SQL Injection Exploitation : Using Alternative Channels
  •  Blind SQL Injection Exploitation : Using Response-Based Techniques
  •  SQL Server 2008 : Using the CLR - Understanding Permission Sets
  •  Registering CLR Assemblies for Use with SQL Server
  •  SQL Server 2008 : What Is the Base Class Library?
  •  Exploring the T-SQL Enhancements in SQL Server 2005 : The WAITFOR Command
  •  Exploring the T-SQL Enhancements in SQL Server 2005 : New Data Types
  •  Exploring the T-SQL Enhancements in SQL Server 2005 : Exception Handling in Transactions
  •  The SQL Server 2008 Configuration Manager
  •  
    Top 10
    A Look At Truecrypt The Open Source Security Tool
    Price Of Piracy
    Acer Aspire 5600U 23" Touchscreen All-in-One PC
    Zalman FX100-Cube Fanless Cooler
    Devolo dLAN LiveCam Starter Kit
    Has Apple Lost It? (Part 2)
    Has Apple Lost It? (Part 1)
    Sony Computer Entertainment (Part 3)
    Sony Computer Entertainment (Part 2)
    Sony Computer Entertainment (Part 1)
    Most View
    AMD A6-3500 - Llano integrated-graphics processors
    Samsung launched projector, smartphone, and 10.1'' note device
    Working with Access and Connectivity Policies in Vista
    Getting the Most Out of the Microsoft Outlook Client : Using Outlook 2007 (part 2) - Sharing Information with Users Outside the Company
    iPhone Application Development : Making Multivalue Choices with Pickers - Understanding Pickers
    Managing Windows Firewall in Windows Vista
    What To Look For When Buying A New Phone Or Tablet (Part 10)
    Delete & Recover Data (Part 4) - Securely Deleting Data Using Eraser 6.0
    The New Domain Names (Part 2)
    Windows Server 2008 : Domain Name System and IPv6 - DNS in Windows Server 2008 R2
    Customizing the Taskbar in Vista
    Kindle Fire HD - Most Advanced 7" Tablet (Part 2)
    Remote Administration of Exchange Server 2010 Servers : RDP with Exchange Server 2010 (part 1) - Planning and Using Remote Desktop for Administration
    Exchange Server 2010 server roles (part 1) - Mailbox Server role
    Nuforce Air DAC Review
    SQL Server 2005 Native XML Web Services : Exposing SQL Programmability as Web Services (part 1)
    SQL Server 2008 : Working with Multiple-Source Queries - Using Linked Servers
    Nintendo WII U - Modern HD Gaming Console (Part 5)
    SQL Server 2008 R2 : Creating and Managing Indexes - Creating Indexes (part 2) - Creating Indexes with SSMS
    Adobe InDesign CS5 : Importing Graphic Objects (part 3) - Using the Image Import Options Dialog Box