Sams Microsoft SQL Server 2008- P6

50 423 0
Sams Microsoft SQL Server 2008- P6

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ptg 231 Tablix (New in 2008) = Table, Matrix, List 13 FIGURE 13.11 Simple Tablix design. To properly color the entire row (or column), you can use the following expression in the BackgroundColor property of the innermost group, where RowGroup1 is the name of the row group: =IIF(Not InScope(“RowGroup1”), “LightGrey”, “White”) Because a cell in a Tablix contains one or more report items, you format the result by formatting those items. For example, a cell that presents textual information contains a Textbox report item. By setting properties and formatting text in a Textbox report item, you can manipulate the rendering outcome. For example, you can conditionally hide row data by setting the Hidden property of each cell to True . Chapter 14 shows an example of this. We frequently use several properties of a Tablix in our work. To set these properties, select the entire Tablix by either clicking the Tablix’s corner handler or selecting the Tablix from the drop-down list on the Properties window. The frequently used properties are as follows: . Filters: A set of filter expressions for a Tablix. Filters limit data displayed by a Tablix much like the WHERE clause limits results of a query. Whereas in most of the cases you want to actually leverage a WHERE clause to improve performance and reduce unnecessary network traffic, you still need to have a filter (for example, in situations when you can’t change a data set). . FixedColumnHeaders and FixedRowHeaders: When set to True , these keep column and row headers displayed when the user scrolls through Tablix. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 232 CHAPTER 13 Working with Report Items . GroupsBeforeRowHeader: Skips the specified number of column groups before displaying row headers. Tablix will display columns of data and then row headers. . LayoutDirection: A direction of column expansion. Left to right ( LTR , default) or right to left ( RTL ). . NoRowsMessage: When a data set returns no results, SSRS renders this message rather than an empty data region. . OmitBorderOnPageBreak: Determines the border display when a report item spans multiple pages. . RepeatRowHeaders and RepeatColumnHeaders: When True , SSRS will repeat column and row headers for a Tablix that spans multiple pages. . SortExpressions: A set of sort expressions for a whole Tablix. You can also define sort expressions for a group. Practical Application of Report Items It is time to put your knowledge to practical use. By now, you have sufficient knowledge to put fairly complex reports together. Let’s create a Sales Order summary report. Adventure Works’s management requested a report that displays selected properties of an order header (ship and bill to addresses, contact information, and billing summary) and selected properties of an order’s line items (product name, unit price, order quantity, and line total). Adventure Works requires each report to have a company logo. To meet these requirements, let’s complete the following steps: 1. Create a new report. For the purpose of this exercise, we will reuse the AdventureWorks shared data source that we created in earlier chapters. From the Report Data window, select New, Data Source. Name the data source AdventureWorks , select the Use Shared Data Source Reference option and choose AdventureWorks. (Yes, both data sources can have the same name.) 2. In the Report Data window, right-click the AdventureWorks data source and select Add Dataset. Name the data set Order_Header . Order_Header will contain data selected from a join between SalesOrderHeader , Address , and StateProvince tables. 3. To have a more complete picture of an order and include both shipping and billing addresses, you need to include Address and StateProvince tables twice in the Order_Header data set. Create aliases for the first set of Address and StateProvince tables as BillToAddress and StateProvinceBill , and use ShipToAddress and StateProvinceShip aliases for the second set of tables. To create an alias for a table, right-click a table in a Graphical Query Designer, select Properties from the shortcut menu, and fill the Alias field as needed. Alternatively, you can edit the query text directly. 4. Create an alias for each field you want to include on a report. You can prefix fields with Ship or Bill for tables related to shipping and billing addresses, respectively. For our sample, we have included the following fields from SalesOrderHeader table: From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 233 Practical Application of Report Items 13 OrderDate , TaxAmt , SubTotal , Freight , TotalDue , Comment , ShipDate . We also included the following fields from Address (and StateProvince ) tables: AddressLine1 , City , PostalCode , and StateProvinceCode (this is from StateProvince table). Based on whether the address is shipping or billing, we have prefixed aliases for the fields with Ship or Bill, correspondingly. 5. Create an Order_Detail data set. This data set contains data selected from a join between SalesOrderHeader . (This table will provide a cross-reference between SalesOrderNumber and SalesId , SalesOrderDetail , and Product tables.) The fields that we have selected for our sample are SalesOrderDetail.OrderQty , SalesOrderDetail.UnitPrice , SalesOrderDetail.LineTotal , Product.Name . 6. To retrieve a specific order, let’s use parameter @SalesOrderNumber in the WHERE clause of both data sets: WHERE SalesOrderHeader.SalesOrderNumber = @SalesOrderNumber). The resulting queries are as follows: Order_Header SELECT Sales.SalesOrderHeader.OrderDate, Sales.SalesOrderHeader.TaxAmt, Sales.SalesOrderHeader.SubTotal, Sales.SalesOrderHeader.Freight, Sales.SalesOrderHeader.TotalDue, Sales.SalesOrderHeader.Comment, Sales.SalesOrderHeader.ShipDate, BillToAddress.AddressLine1 AS BillAddressLine1, BillToAddress.City AS BillCity, BillToAddress.PostalCode AS BillPostalCode, StateProviceBill.StateProvinceCode AS BillStateProvinceCode, ShipToAddress.AddressLine1 AS ShipAddressLine1, ShipToAddress.City AS ShipCity, ShipToAddress.PostalCode AS ShipPostalCode, StateProviceShip.StateProvinceCode AS ShipStateProvinceCode FROM Sales.SalesOrderHeader INNER JOIN Person.Address AS BillToAddress ON Sales.SalesOrderHeader.BillToAddressID = BillToAddress.AddressID AND Sales.SalesOrderHeader.ShipToAddressID = BillToAddress.AddressID AND Sales.SalesOrderHeader.BillToAddressID = BillToAddress.AddressID AND Sales.SalesOrderHeader.ShipToAddressID = BillToAddress.AddressID INNER JOIN Person.StateProvince AS StateProviceBill ON BillToAddress.StateProvinceID = StateProviceBill.StateProvinceID INNER JOIN Person.Address AS ShipToAddress ON Sales.SalesOrderHeader.BillToAddressID = ShipToAddress.AddressID AND Sales.SalesOrderHeader.ShipToAddressID = ShipToAddress.AddressID AND Sales.SalesOrderHeader.BillToAddressID = ShipToAddress.AddressID AND Sales.SalesOrderHeader.ShipToAddressID = ShipToAddress.AddressID AND Sales.SalesOrderHeader.BillToAddressID = ShipToAddress.AddressID AND Sales.SalesOrderHeader.ShipToAddressID = ShipToAddress.AddressID AND From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 234 CHAPTER 13 Working with Report Items StateProviceBill.StateProvinceID = ShipToAddress.StateProvinceID INNER JOIN Person.StateProvince AS StateProviceShip ON BillToAddress.StateProvinceID = StateProviceShip.StateProvinceID AND ShipToAddress.StateProvinceID = StateProviceShip.StateProvinceID WHERE Sales.SalesOrderHeader.SalesOrderNumber = @SalesOrderNumber Order_Detail SELECT Sales.SalesOrderDetail.OrderQty, Sales.SalesOrderDetail.UnitPrice, Sales.SalesOrderDetail.LineTotal, Production.Product.Name FROM Sales.SalesOrderHeader INNER JOIN Sales.SalesOrderDetail ON Sales.SalesOrderHeader.SalesOrderID = Sales.SalesOrderDetail.SalesOrderID INNER JOIN Production.Product ON Sales.SalesOrderDetail.ProductID = Production.Product.ProductID WHERE Sales.SalesOrderHeader.SalesOrderNumber = @SalesOrderNumber 7. Add the company logo image report item. From Windows File Explorer, drag the image item and drop it onto the report body. Change the name to Logo . (Refer back to Figure 13.1 to see the Image Properties dialog box.) 8. Add a list by dragging a List item from the Toolbox. As you remember, List is a template for Tablix. You can take advantage of the Dataset property of the List item to avoid typing scope resolution for each of the simple report items, such as Textboxes, included on the List report item. 9. As an experiment, drag and drop the ShipCity field of Order_Header outside of the List item. Note the value of the text box outside of the list is =First(Fields!ShipCity.Value, “Order_Header”) . As a comparison, drag and drop the ShipCity field on the list. Note the value of the created text box is =Fields!ShipCity.Value . Also note that the DataSetName property of the list is now set to Order_Header , and it was blank originally. Be careful when dropping fields from other data sets to a list. If you do so, BIDS will update DataSetName to the data set associated with the last drop, potentially invalidating the scope resolution for other items. 10. Add a report heading. Drag and drop a text box from the Toolbox. Enter the follow- ing expression as a value: =”Sales Order Number” & “ - “ & First(Fields!SalesOrderNumber.Value, “Order_Header”) . This expression concate- nates the constant ”Sales Order Number - SO#####” and the value of the SalesOrderNumber field. To highlight the heading of the report, increase the font size and change the text box background. 11. Add and arrange data fields in the page header by dragging and dropping data set fields on the list: Street, City, State, and Zip from both billing and shipping addresses. Second, add billing summary fields. Add Textbox items to title values that From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 235 Chart Repor t Item (Improved in 2008) 13 were added, such as a text box stating Ship To Address. Change the heading for information sections to bold font. 12. Add lines to help separate informational pieces as necessary. Note that not all the web browsers support overlapping controls, such as lines. If you need to cross lines, you might need to have several lines bordering each other. 13. Add a table to display details of an order. Drag and drop a Table item from the Toolbox. The default table has three rows and three columns. Drag and drop the Order_Detail fields to the Detail area of the table, and note how the heading is changed to the name of the field. 14. To summarize line-item charges, right-click the detail row and select Insert Row, Outside Group Below from the context menu. This row becomes a footer of the table. 15. In the rightmost cell of the row, enter the following summarization expression: =Sum(Fields!LineTotal.Value) . The resulting design-time view of the report should look similar to Figure 13.12. Chart Report Item (Improved in 2008) A Chart report delivers a graphic presentation of data from a single data set. Chart has comprehensive functionality and has similar capabilities to an Excel chart, including a variety of chart types, 3D effects, trend lines, and more. FIGURE 13.12 Design picture of the Sales Order Summary repor t. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 236 CHAPTER 13 Working with Report Items Microsoft significantly overhauled chart capabilities in SSRS 2008 and added the following: . New chart types, such as bar/column cylinder, pyramid, funnel, polar, radar, stock, candlestick, range column, range bar, smooth area, smooth line, stepped line, box plot, Pareto, and histogram. . Secondary axes support. . Calculated series functionality that allows you to select 15 commonly used calcula- tions, including statistical analysis, moving averages, and financial indicators. . More control over common chart elements like Legends , Titles , Axes (such as custom axis intervals, reverse direction, set alternating bands on a chart [interlaced lines]), and Labels (such as automatic label interval to avoid collisions, customizable rotation angles, font size, and text-wrap properties for axis label calculations). . New interface and new, more appealing chart design. . Support of multiple chart areas, multiple legends, and multiple titles on the same chart. The Chart control used in this release of Reporting Services is licensed from Dundas Software (www.dundas.com). You can obtain an add-on pack for Reporting Services from Dundas Software. Figure 13.13 shows a design-time view of a chart after you click the design surface of the chart. Note the three drop areas: Series, Category and Data. Unlike the previous version, the Chart Properties dialog box no longer provides compre- hensive control over a chart’s properties. A chart’s context menu provides an interface to access properties for various chart components. To access this menu, right-click a chart to display a shortcut menu. This shortcut menu enables you to access various components of a chart (see Figure 13.14). Chart Data (Value) A chart requires at least one set of data values associated with it. You can simply drag and drop a field to the Design area (it has a Drop Data Fields Here note) of a chart. The data determines the y-axis value. For example, for a column chart, the data determines the height of a column. Data is considered static. For a column chart, it means that a single data file added to a chart (and no series) results in a single column providing a sum of all values and a single legend. If you add one more data fields to a chart, SSRS shows a second column and adds a second legend. In most charts, we group data by a series or a category. In this case, you must use an aggregate expression for a data value. This is similar to grouping in a Tablix where non- aggregate expressions are syntactically allowed. However, the result contains the last value of a field rather than a summary value for a group and, therefore, produces an unexpected result. Report Designer automatically adds an aggregate function, but changes are allowed. To verify or change the data value expression, you can right-click a field you added and select Series Properties from the context menu. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 237 Chart Repor t Item (Improved in 2008) 13 Data field Minor gridlines appear here when set up Category field Axis label categoryAxis label categoryAxis label categoryAxis label categoryAxis label category Data Point label appears like this when set up Minor tick marks appear between major tick marks when set up Major tickmark Major tickmarkMajor tick mark Major gridline Major gridlineMajor gridline Legend 98.5 Axis label value Series Data Point marker will be here when set up FIGURE 13.13 Design-time picture of a chart. Chart can display only numeric data. You can convert formatted strings (such as ”123.123” ) to numbers either in a query or using SSRS expressions. Different chart types handle Null (or empty) values from a data set differently: In an X-Y graphic chart, you will have gaps for empty values, for example, and a nonlinear chart (such as pie, doughnut, funnel, or pyramid) simply skips the display of Null values. You can eliminate Null values in a query or through expressions. Alternatively, you can use the chart’s empty-point-handling capability: 1. On the chart’s design surface, click the series that contains Null values. BIDS displays properties for the series in the Properties pane. 2. Expand the EmptyPoint node and set the Color property. 3. In the EmptyPoint node, expand the Marker node. 4. Under the Marker node, set the MarkerType property. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 238 CHAPTER 13 Working with Report Items FIGURE 13.14 Chart context menu. NOTE Some chart types handle empty points automatically, by either connecting across a missing point or simply skipping a display of a missing value altogether. Table 13.6 provides partial RDL of Chart Data. From this point forward in this book, the section surrounded by the <ChartData> tag is abbreviated as {CHART DATA} . TABLE 13.6 Partial Set of Tags for Char t Data RDL Element Explanation <ChartData> Begin the Chart Data section. <ChartSeriesCollection> Collection of series. Each series in a collection has associated data points and describes how those points look on a chart. <ChartSeries Name=”Standard- Cost”> <ChartDataPoints> <ChartDataPoint> <ChartDataPointValues> <Y> =Sum(Fields!Standard- Cost.Value) Names comes from a data field associated with a series, the value from the StandardCost field. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 239 Chart Repor t Item (Improved in 2008) 13 Chart Series Data series are optional and when added create series labels that are placed in the legend of the chart. Series groups are dynamic. A chart that uses series groups displays a chart element for each series group for each category. For example, a column chart with sales data displays a column for each year returned by a series group expression. Following is the RDL that describes series. From this point forward, the section surrounded by the <ChartSeriesHierarchy> tag is abbreviated as {CHART SERIES}: <ChartSeriesHierarchy> <ChartMembers> <ChartMember> <Group Name=”Chart4_SeriesGroup1”> <GroupExpressions> <GroupExpression>=Fields!Name.Value</GroupExpression> </GroupExpressions> </Group> <Label>=Fields!Name.Value</Label> </ChartMember> </ChartMembers> </ChartSeriesHierarchy> TABLE 13.6 Continued Element Explanation <ChartDataLabel> <Label> =Sum(Fields!ProductID.Value, “ProductCostHistory”) Each point on chart can have a label. It is common to see an actual value next to a data point. <ChartMarker> Allows formatting a marker. A marker is a graphical highlight of a data point on a graph. On a line chart, a marker enables you to highlight the difference between a connector line and the actual data. <Type>Line</Type> Chart type. In this case, it is Line . <ChartEmptyPoints> Describes how to handle empty or null data in a series. <ValueAxisName>Primary <CategoryAxisName>Primary Axes and series association. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 240 CHAPTER 13 Working with Report Items Chart Category Chart Category Groups is the optional mechanism of grouping data that provides the labels for chart elements. For example, in a column chart, Country Name fields placed in the Category region gener- ate country labels for x-axes (United States, Italy, and so forth). You can nest categories. Multiple categories nest x-axes labels. For example, in a column chart with sales data, the first category group could be a county, and the second category group could be TerritoryId. The column chart would display groupings of products by TerritoryId on the x-axis. Following is the RDL that describes a category grouping. From this point forward, the section surrounded by the <ChartCategoryHierarchy> tag is abbreviated as {CHART CATEGORY} : <ChartCategoryHierarchy> <ChartMembers> <ChartMember> <Group Name=”Chart4_CategoryGroup1”> <GroupExpressions> <GroupExpression>=Fields!StartDate.Value</GroupExpression> </GroupExpressions> </Group> <Label>=Fields!StartDate.Value</Label> </ChartMember> </ChartMembers> </ChartCategoryHierarchy> Chart Areas The Chart area contains the plotting area of a chart and axes related items such as axes labels and axes titles. A single chart may have multiple areas, but contains only one area by default. A data series could be connected to only one area through the ChartArea, Name property. When you add a new series, BIDS automatically assigns ChartArea, Name = Default . You will need to change ChartArea, Name property to associate series with a different Chart area. While you can combine most of the charts types (like line and column) on a single Chart area, for some (such as bar, polar, and shape) you may need to add a new area to accom- modate them. Table 13.7 provides a partial list of a chart area’s RDL elements. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... SQL for grouping (GROUP BY) provides the best performance However, a static SQL statement is not very flexible The SQL statement might be too complex, lose its elegance, and, especially, it may not provide the required formatting In addition, complex SQL queries are hard to maintain and troubleshoot The following are some tips to help strike a balance between the grouping capabilities of SSRS and SQL: ... properly placed space is crucial, such as the space between ORDER BY and a parameter Query design has to follow best practices to avoid SQL injection You can find a good article about avoiding SQL injection attacks at http://msdn .microsoft. com/msdnmag/ issues/04/09/SQLInjection/ Data Region and Group Sorting A report developer can implement sorting for a group or for a data region by providing one or... plenty of capacity on the database server In many cases, it will not be an issue for a database server with sufficient capacity, but do consider performance Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark From the Library of STEPHEN EISEMAN Sorting, Including Interactive Sorting and Data Source Sorting 255 implications for the database server In addition, because the query... query, unless needed for GROUP BY A conversion function is called for each row of returned data, which adds an unnecessary burden to a database server Because database servers are much harder to scale out using inexpensive commodity hardware than reporting servers, it makes sense to have conversion and formatting performed by SSRS For example, the following query retrieves a summary of all line items... further explore this functionality by adding more interactive sort fields and observing changes in rendered HTML and the report’s URL Keep in mind that it is also possible to make dynamic SQL and leverage the data source server for runtime sorting In most cases, however, SSRS built-in interactive sorting will be more efficient overall, easier to develop and maintain, and thus more elegant Scope Parameter... and Chart Most scenarios employ grouping in SSRS to aggregate data and generate summary information Concepts applicable to aggregation in SSRS are similar to those applicable to the GROUP BY clause in a SQL query However, unlike a query, Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark From the Library of STEPHEN EISEMAN 252 CHAPTER 14 Grouping, Sorting, Aggregating Data, and... grouping expressions The Page Breaks tab allows you to specify how a group affects the report’s pagination The Sorting tab specifies how the data within a group is sorted (similar to ORDER BY in Transact -SQL) The Visibility tab specifies the initial visibility of the group and an item that can interactively trigger visibility If you need to exclude group items from a display on a report, you must use the... sorts data regions and groups that have the SortExpressions property set This option will re-sort data returned by a data set This option is useful when you need to offload sort processing from a database server, when you need to leverage a single data set to display data in a specific order, or when you need to to fine-tune sorting within a group Use interactive sort functionality (HTML-rendered reports... =IIF(InScope(“OrderLineItem”), “Underline”, “None”) Summary Grouping and sorting functionality allow SSRS to perform much more complex data manipulations than a query When there is sufficient data source server capacity and for the best performance, use GROUP BY and ORDER BY in a query Data regions provide additional options to sort and group data In a way, grouping and sorting functionality is similar... General formatting Format Text formatting Color Direction FontFamily FontSize FontStyle FontWeight TextDecoration WritingMode Calendar Line Height Locale control Language NumeralLanguage NumeralVariant The Microsoft NET Framework formatting string to apply to the item For example, C for currency The calendar to use to format dates Used in conjunction with the Language property The color (Red), direction, . www.verypdf.com to remove this watermark. ptg 236 CHAPTER 13 Working with Report Items Microsoft significantly overhauled chart capabilities in SSRS 2008 and added

Ngày đăng: 07/11/2013, 12:15

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan