Megosztás a következőn keresztül:


Lesson 3: Creating a Report Model-Based Query

In this lesson, you will build a query that indicates the product sales by year and quarter. You will add six fields to the query, and then apply a filter so that only data on or after 5/1/2003 is returned. The query you are about to design is the same query that is used for the SQL Server 2008Report Builder sample report titled Product by Sales Year.

To open the Query Designer window

  1. In Solution Explorer, right-click Reports and then select Add New Report.

    The Report Wizard opens.

  2. Click Next.

    The Select the Data Source page appears.

  3. In the Shared data source drop-down list, select RMQBdatasource.

  4. Click Next.

  5. On the Design the Query page, click Query Builder.

    The Query Designer window opens. Note that this window looks similar to Report Builder. On the left is a list of entities and their respective fields that you can add to your query. To the right of the entities list is a drop zone. To build your query, drag the entities and fields that you want to use in your query to this area. To the right of the fields list is the results pane; you can run your query and view the returned results at any time.

To build the query

  1. In the Entities list of the Query Builder window, select Product.

  2. From the Fields list, select the Product Category field, and drag it to the query area.

  3. From the Fields list, drag the Product Subcategory field to the right edge of the Product Category field.

  4. From the Fields list, drag the Name field to the right edge of the Product Subcategory field.

  5. In the Entities list, click Sales, and then click Sales Order.

  6. In the Fields list, expand the Order Date field.

  7. From the Fields list, drag the Order Year field to the right edge of the Name field.

  8. From the Fields list, drag the Order Quarter field to the right edge of the Order Year field.

  9. From the Fields list, drag the Sum Total Due field to the right edge of the Order Quarter field.

    You have added all the fields that you need and your query should look similar to the following picture.

    A report model-based query in Query Designer.

    Next, you will apply a filter to the query.

To apply a filter

  1. On the Query Designer toolbar, click Filter.

    The Filter Data dialog box opens.

  2. In the Entities list, click Product.

  3. In the Fields list, double-click Product Category.

  4. In the filter clause, click equals and then select in a list.

  5. Click no values selected, and then select Accessories, Bikes, and Clothing.

    Only sales data for these products will be returned in the rendered report.

  6. In the Entities list, select Sales Order.

  7. In the Fields list, double-click Order Date.

  8. In the filter clause, click Order Date and then select Prompt.

  9. Right-click equals, and then select on or after.

  10. In the drop-down box, type or select 5/1/2003.

  11. Click OK.

    You have successfully applied a filter to the report query so that only sales of accessories, bicycles, and clothing that occurred on or after 5/1/2003 are displayed when a report viewer is prompted to enter a specific sales date. Next, you will return to the Report Wizard.

To return to the Report Wizard

  • In the Query Designer, Click OK.

    The Design the Query page of the Report Wizard appears again. The query you just created is in the Query string box.

Next Steps

Next, you need to design your report. In the next lesson, you will select a report structure and style, and add totals to the report. See Lesson 4: Designing the Report.