This post will help you create a basic table report based on the AdventureWorks2008R2 database using Report Designer. You can also use Report Builder or the Report Wizard to create reports. In this post, you will create a report project, set up connection information, define a query, add a Table data region, group and total some fields, and preview the report.
Create a report server project
Click Start, point to Programs, point to Microsoft SQL Server 2008 R2, and then click Business Intelligence Development Studio.
On the File menu, point to New, and then click Project.
In the Project Types list, click Business Intelligence Projects.
In the Templates list, click Report Server Project.
In Name, type Tutorial.
Click OK to create the project.
The Tutorial project is displayed in Solution Explorer.
Create a new report definition file
In Solution Explorer, right-click Reports, point to Add, and click New Item.
In the Add New Item dialog box, under Templates, click Report.
In Name, type Sales Orders.rdl and then click Add, Report Designer opens and displays the new .rdl file in Design view.
Set up a connection
In the Report Data pane, click New and then click Data Source ( If the Report Data pane is not visible, from the View menu, click Report Data ).
In Name, type AdventureWorks2008R2.
Make sure Embedded connection is selected.
In Type, select Microsoft SQL Server.
In Connection string, type the following:
Data source=localhost; initial catalog=AdventureWorks2008R2
This connection string assumes that Business Intelligence Development Studio, the report server, and the AdventureWorks2008R2 database are all installed on the local computer and that you have permission to log on to the AdventureWorks2008R2 database.
If you are using SQL Server Express with Advanced Services or a named instance, the connection string must include instance information:
Data source=localhost\SQLEXPRESS; initial catalog=AdventureWorks2008R2
Click OK. A data source called AdventureWorks2008R2 is added to the Report Data pane.
Define a Transact-SQL query for report data
In the Report Data pane, click New, and then click Dataset. The Dataset Properties dialog box opens.
In the Name box, type AdventureWorksDataset.
Click the Use a dataset embedded in my report radio button. Make sure the name of your data source, AdventureWorks, is in the Data source text box, and that the Query type is Text.
Type, or copy and paste, the following Transact-SQL query into the Query box.
soh.OrderDate AS [Date],
soh.SalesOrderNumber AS [Order],
pps.Name AS Subcat, pp.Name as Product,
SUM(sd.OrderQty) AS Qty,
SUM(sd.LineTotal) AS LineTotal
FROM Sales.SalesPerson sp
INNER JOIN Sales.SalesOrderHeader AS soh
ON sp.BusinessEntityID = soh.SalesPersonID
INNER JOIN Sales.SalesOrderDetail AS sd
ON sd.SalesOrderID = soh.SalesOrderID
INNER JOIN Production.Product AS pp
ON sd.ProductID = pp.ProductID
INNER JOIN Production.ProductSubcategory AS pps
ON pp.ProductSubcategoryID = pps.ProductSubcategoryID
INNER JOIN Production.ProductCategory AS ppc
ON ppc.ProductCategoryID = pps.ProductCategoryID
GROUP BY ppc.Name, soh.OrderDate, soh.SalesOrderNumber, pps.Name, pp.Name,
HAVING ppc.Name = 'Clothing'
(Optional) Click the Query Designer button. The query is displayed in the text-based query designer. You can toggle to the graphical query designer by clicking Edit As Text. View the results of the query by clicking the Run (!) button on the query designer toolbar.
You see the data from six fields from four different tables in the AdventureWorks2008R2 database. The query makes use of Transact-SQL functionality such as aliases. For example, the SalesOrderHeader table is called soh.
Click OK to exit the query designer.
Click OK to exit the Dataset Properties dialog box.
Your AdventureWorksDataset dataset fields appear in the Report Data pane.
Adding a Table to the Report (Reporting Services)
To Add a Table data region and fields to a report layout
In the Toolbox, click Table, and then click on the design surface. Report Designer draws a table data region with three columns in the center of the design surface.
The Toolbox may appear as a tab on the left side of the Report Data pane. To open the Toolbox, move the pointer over the Toolbox tab. If the Toolbox is not visible, from the View menu, click Toolbox.
In the Report Data pane, expand the AdventureWorksDataset dataset to display the fields.
Drag the Date field from the Report Data pane to the first column in the table.
When you drop the field into the first column, two things happen. First, the data cell will display the field name, known as the field expression, in brackets: [Date]. Second, a column header value is automatically added to Header row, just above the field expression. By default, the column is the name of the field. You can select the Header row text and type a new name.
Drag the Order field from the Report Data pane to the second column in the table.
Drag the Product field from the Report Data pane to the third column in the table.
Drag the Qty field to the right edge of the third column until you get a vertical cursor and the mouse pointer includes a plus sign [+]. When you release the mouse button, a fourth column is created for [Qty].
Add the LineTotal field in the same way, creating a fifth column.
The column header is Line Total. Report Designer automatically creates a friendly name for the column by splitting LineTotal into two words.
The following diagram shows a table data region that has been populated with these fields: Date, Order, Product, Qty, and Line Total.
Preview Your Report
Previewing a report enables you to easily view the rendered report without having to first publish it to a report server. You will probably want to preview your report frequently during design time.
To Preview a report
Click the Preview tab. Report Designer runs the report and displays it in Preview view.
The following diagram shows part of the report in Preview view.
Notice that the currency (in the Line Total column) has six places after the decimal, and the date has an unnecessary time stamp. You're going to fix that formatting in the next lesson.
Now that you've added a table and some fields to the Sales Orders report, you can format the date and currency fields and the column headers.
Format the Date
The Date field displays date and time information by default. You can format it to display only the date.
Format a date field
Click the Design tab.
Right-click the cell with the [Date] field expression and then click Text BoxProperties.
Click Number, and then in the Category field, select Date.
In the Type box, select January 31, 2000.
Format the Currency
The LineTotal field displays a general number. Format it to display the number as currency.
To format a currency field
Right-click the cell with the [LineTotal] field expression and then click Text BoxProperties.
Click Number, and in the Category field, select Currency.
If your regional setting is English (United States), the defaults should be:
Decimal places: 2
Negative numbers: ($12345.00)
Symbol: $ English (United States)
Select Use 1000 separator (,).
If the sample text is: $12,345.00, then your settings are correct.
Change Text Style and Column Widths
You can also change the formatting of the header row to differentiate it from the rows of data in the report. Lastly, you will adjust the widths of the columns.
To format header rows and table columns
Click the table so that column and row handles appear above and next to the table.
The gray bars along the top and side of the table are the column and row handles.
Point to the line between column handles so that the cursor changes into a double-headed arrow. Drag the columns to the size you want.
Select the row containing column header labels and from the Format menu, point to Font and then click Bold.
To preview your report, click the Preview tab. It should look something like this:
Grouping Data in A report
To group data in a report
Click the Design tab.
From the Report Data pane, drag the Date field to the Row Groups pane. Place it above the row called Details.
Note that the row handle now has a bracket in it, to show a group. The table now also has two Date columns -- one on either side of a vertical dotted line.
From the Report Data pane, drag the Order field to the Row Groups pane. Place it below Date and above Details.
Note that the row handle now has two brackets in it, to show two groups. The table now has two Order columns, too.
Delete the original Date and Order columns to the right of the double line. This removes this individual record values so that only the group value is displayed. Select the column handles for the two columns, right-click and click Delete Columns.
You can format the column headers and date again.
Switch to the Preview tab to preview the report. It should look similar to the following illustration:
To add totals to a report
Switch to Design view.
Right-click the data region cell that contains the field [LineTotal], and click Add Total.
This adds a row with a sum of the dollar amount for each order.
Right-click the cell that contains the field [Qty], and click Add Total.
This adds a sum of the quantity for each order to the totals row.
In the empty cell to the left of Sum[Qty], type the label "Order Total".
You can add a background color to the totals row. Select the two sum cells and the label cell.
On the Format menu, click Background Color and click Light Gray.
To add a daily total to a report
Right-click the Order cell, point to Add Total, and click After.
This adds a new row containing sums of the quantity and dollar amount for each day, and the label "Total" in the Order column.
Type the word Daily before the word Total in the same cell, so it reads Daily Total.
Select the Daily Total cell, the two Sum cells and the empty cell between them.
On the Format menu, click Background Color and click Orange.
To add a grand total to a report
Right-click the Date cell, point to Add Total, and click After.
This adds a new row containing sums of the quantity and dollar amount for the entire report, and the Total label in the Date column.
Type the word Grand before the word Total in the same cell, so it reads Grand Total.
Select the Grand Total cell, the two Sum cells and the empty cells between them.
On the Format menu, click Background Color and click Light Blue.
The last page should look something like this, although your Order Total, Daily Total, and Grand Total may be on a second page: