For a SQL Server data source, you can use the text-based query designer or the graphical query designer to help specify a query for your dataset. When you specify the query for a new dataset, the graphical query designer opens by default. If the existing dataset query is too complex to view in the graphical query designer, the text-based query designer opens. Both query designers support the following query types: Text and StoredProcedure. You specify the type of query in the Dataset Properties dialog box before you open the query designer.
For query type Text, if you include query parameters in your query text, Reporting Services creates corresponding report parameters. For query type StoredProcedure, if your stored procedures has input parameters, Reporting Services creates corresponding report parameters. For more information about query parameters and report parameters, see Using Query Parameters later in this topic.
For more information about each query designer, see Text-based Query Designer User Interface and Graphical Query Designer User Interface.
Using Query Type Text
When the query designer opens in Text mode, you can type Transact-SQL commands to define the data in a dataset. For example, the following Transact-SQL query selects all the names of all employees.
SELECT FirstName, LastName
FROM HumanResources.Employee E INNER JOIN
Person.Contact C ON E.ContactID=C.ContactID
Click the Run button (!) on the toolbar to run the query and display the results in the Result pane.
You can also import existing queries from another report or from sql files.
Using Query Type StoredProcedure
When the query designer opens in StoredProcedure mode, you have already selected the stored procedure to use when you specified StoredProcedure in the Dataset Properties dialog box.
If you already know the name of a different stored procedure you want to run, you can replace the existing text and type the new stored procedure name in the query pane.
Reporting Services supports stored procedures that return only one set of data. If a stored procedure returns multiple result sets, only the first one is used.
If a stored procedure has a parameter with a default value, you can access that value in Reporting Services by using the DEFAULT keyword as a value for the parameter. If the query parameter is linked to a report parameter, the user can type or select the word DEFAULT in the input box for the report parameter. For more information, see Stored Procedures (Database Engine).
Using Query Parameters
For query text that contains parameters or for stored procedures with input parameters, Report Designer automatically creates corresponding report parameters in the report definition when you run the query. When the report runs, values for the report parameters are passed to the query parameters. For example, the following SQL query creates a report parameter named EmpID:
SELECT FirstName, LastName FROM HumanResources.Employee E INNER JOIN
Person.Contact C ON E.ContactID=C.ContactID
WHERE EmployeeID = @EmpID
You can manage the relationship between report parameters and query parameters by using Dataset Properties Dialog Box, Parameters. Queries with parameters that are linked to report parameters do not require the DECLARE statement.
Although report parameters are created automatically from query parameters, you manage report parameters separately in the Report Data pane.
Note: |
|---|
|
If you change the name of a query parameter or delete a query parameter, the report parameter that corresponds to the query parameter is not automatically changed or deleted. You can remove or change the order of report parameters by using buttons in the Report Data pane toolbar . For more information, see Adding Parameters to Your Report.
|