Tải bản đầy đủ (.pdf) (50 trang)

Sams Microsoft SQL Server 2008- P5

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.65 MB, 50 trang )

ptg
181
Types of Data Sources
Report-Specific Data Sources
The report-specific data source should be used only when the data needed to process a
report should be restricted to that report. If multiple reports need to access the same data
source with the same credentials, you should use a shared data source. This is because
maintaining lots of embedded data sources can be cumbersome. After the report has been
published to the Report Server, the embedded data source has to be maintained as part of
that report. You can use the Report Manager web interface to change the reference from
an embedded to a shared data source.
Shared Data Sources
A shared data source exists on the Report Server as a separate entity. Report developers can
define a shared data source in Visual Studio, but it does not overwrite an existing data
source by default in the same manner that it overwrites reports. To override a shared data
source, you have to set
OverwriteDataSources
project property to
True
(see Figure 11.1).
11
A shared data source is useful when
. Many reports use data from the same location with the same credentials.
. An administrator needs to have an easy way to change the location of a data source
for several reports. This is the case, for example, when moving reports from develop-
ment to production.
Data Source Expressions
An expression can be used to define the connection at runtime. A classic case is the differ-
ence between an active online transaction processing (OLTP) database and historical data
or a data warehouse. Many companies store historical data that is more than six months
FIGURE 11.1


OverwriteDataSources
project property.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
182
old in a data warehouse. You would have to determine an appropriate connection from
some report-level parameter.
Like all expressions, a data source expression would have to be written in Visual Basic.NET
and preceded by an equals (=) sign.
To define data source expressions, consider the following guidelines:
. Do not use a shared data source. You cannot use a data source expression in a shared
data source. You must define a report-specific data source for the report instead.
. Design the reports using a static connection string.
. Do not include credentials in the connection string. When possible, Windows authen-
tication is the best way to handle credentials. You can also hard code the credentials
through the Data Source Properties dialog box (as discussed later in this chapter).
. Use a report parameter to specify the values to be passed to the expression. The para-
meter can pull from a list of valid values from a query using a separate data source.
Later in this chapter, you will see how to set up parameter dependencies that enable
you to do this.
. Make sure all the data sources implement the same schema.
. Before publishing the report, replace the static connection string with an expression.
The following is an example of an expression-based data source for SQL Server:
=”Data Source=” &Parameters!DBServer.Value & “;Initial Catalog=NorthWind
The preceding example assumes that there is a parameter called
DBServer
.
Data Source Credentials
You have several options to supply credentials for a data source (see Figure 11.2):

. Windows authentication (integrated security). It is the easiest to use, and the creden-
tials are handled separately from the data sources. Using this option, you are also
leveraging time-tested Windows security. Because each Windows user has individual
credentials, you can assign security restrictions down to a level of an individual user.
You can also leverage Windows security groups to handle several users as a group
with the same level of permissions. For example, you can set permissions in such a
way that an employee’s personal information is available only to the HR group and
the employee herself.
. Hard-code the credentials. In this case, you just enter login credentials. Report
Designer stores encrypted credentials separately from the data source, locally and in
the file
ProjectName.rptproj.user
and then in the Reporting Services database, also
in the encrypted form.
. Prompt a user for login credentials.
CHAPTER 11 Accessing Data
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
183
FIGURE 11.2
Shared Data Source Properties dialog box, Credentials tab.
Connection Strings
11
. Use the No Credentials option. This is used for data sources that do not require
credentials.
. Hard-code credentials in the connection string (not recommended). This approach is
not recommended because of the security implications associated with this method.
Because the credentials are not encrypted, this approach can easily lead to unautho-
rized information access.

Connection Strings
Connection strings vary widely by the type of processing extensions used in the data set.
For example, if you use the OLE DB or ODBC process, you must specify the driver. For SQL
Server, you should specify a database name, whereas for Oracle the database name is not
required. For XML, just point it to the source by entering a URL in the connection string.
In all cases, you should not specify the credentials used in accessing the data source inside
the connection string. SSRS stores data source credentials separately.
The following are some common connection strings:
NOTE
We use
***Server
to denote a name or an IP address of a server that hosts a data
source. For example,
SQLServer
is the name of a server that hosts a SQL Server data-
base.
In addition to specifying a name or an IP address, you can use the following to point to
a local server:
localhost
,
(local)
, and
.
(dot). All of those work for the .NET
Framework data provider, but only
(local)
works for the SQL OLE DB provider.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg

184
. SQL Server RDBMS. You can connect the .NET Framework data provider, OLE DB
data provider for SQL Server, and ODBC. In general, we do not recommend using
ODBC because in many cases ODBC providers are several times slower than .NET or
OLE DB providers.
. SQL Server 2000 and later, where 1433 is a port number. The SQL Server admin-
istrator sets a port for an instance of SQL Server during configuration process:
Data source=SQLServer\InstanceName,1433;Initial Catalog=DatabaseName
. Microsoft OLE DB provider for SQL Server:
Provider=SQLOLEDB.1;Data Source=(local);Integrated Security=SSPI;Initial
Catalog=AdventureWorks
. Analysis Services. Much like with the SQL server, you can connect using several
different providers:
. The .NET Framework data provider for Analysis Services:
data source= OLAPServer;initial catalog=AdventureWorksDW
. The Microsoft OLE DB provider for OLAP 8.0. You can use it to connect
to SQL Server 2000 and later:
provider=MSOLAP.2;data source=OLAPServer;initial
catalog=AdventureWorksDW
. The Microsoft OLE DB provider for Analysis Services 10.0. You can use it
to connect to SQL Server 2008:
provider=MSOLAP.4;data source= OLAPServer;initial
catalog=AdventureWorksDW
. Oracle. We recommend Oracle using network configuration tools and that you set
an alias for an Oracle server. For example, where the actual server is at
OracleServerAddress:Port/Instance
, you can set an alias as
OracleServer
.
. The .NET Framework data provider for Oracle. Oracle is running on Windows,

and Windows authentication is set up:
Data Source=OracleServer; Integrated Security=Yes;
CHAPTER 11 Accessing Data
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
185
Connection Strings
11
. The OLE DB provider for Oracle:
Data Source=OracleServer;User ID=userId;
Password=userPassword;Provider=OraOLEDB.Oracle.1;Persist Security Info=True;
. XML via URL:
URL=” />. XML via web service:
URL=<url>;SOAPAction=<method-uri>[#|/]<method-name>
URL=http://ReportServer/reportserver/reportservice.asmx;SOAPAction=”http://sche
mas.microsoft.com/sqlserver/2004/05/reporting/reportservices/ListChildren”
NOTE
When specifying XML as a data source, the credentials should be set to Windows
authentication or to No Credentials for anonymous access. Anything else generates an
error during runtime.
. Report model data source for native mode SSRS:
Server=http://ReportServer/reportserver;
datasource=/models/AdventureWorks.smdl
. Report model data source for SSRS in SharePoint integrated mode:
Server=http://ReportServer;
datasource=http://ReportServer/SharePointSite/documents
/models/AdventureWorks.smdl
. SSIS package:
-f c:\packagename.dtsx

. SAP NetWeaver BI data source:
DataSource=http://SAPServer:8000/sap/bw/xml/soap/xmla
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
186
TABLE 11.1
Panes of Graphical Query Designer
Pane Function
Diagram Displays graphic representations of the tables in the query. Use this pane to
select fields and define relationships between tables.
Grid Displays a list of fields returned by the query. Use this pane to define aliases,
sorting, filtering, grouping, and parameters.
. Hyperion Essbase:
Data Source=http://HyperionServer:13080/aps/XMLA;Initial Catalog=SalesDB
. Teradata:
Data Source=TeradataServer;User ID=myUsername;Password=myPassword;
Microsoft supplies additional drivers that are not installed by default with SSRS. For
example, the Microsoft SQL Server 2008 feature pack (www.microsoft.com/downloads/
details.aspx?FamilyId=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C&displaylang=en)
comes with an IBM DB2 OLE DB driver install. Once you install it, the report driver shows
Microsoft OLE DB Provider for DB2
in the OLE DB provider list.
Practically all the DBMS vendors supply .NET, OLE DB, or ODBC providers for their data-
bases and supply setup and connection string information. In addition,
Connectionstrings.com provides connection information for a variety of data sources.
Querying Data
After a connection is established, your next step is to query the data source. For most rela-
tional databases, this involves executing some type of SQL query against the catalog. In
the case of Analysis Services, you use Multidimensional Expressions (MDX) queries, and

for data mining, you use Data Mining Extensions (DMX) queries.
The Graphical Query Designer that comes with Report Designer aids developers in devel-
oping queries in any of the preceding languages. For more advanced queries or in cases
when the data source is not relational database management system (RDBMS), you can use
the Generic Query Designer.
Graphical Query Designer
The Graphical Query Designer is a tool to aid in the development of the query. Behind the
scenes, it connects to the data store to pull tables and views. All you have to do is right-
click the top pane to add the table you want and select the columns. If the database has
referential integrity, the Graphical Query Designer picks that up, too, and makes the
necessary joins automatically. You can also join database tables by dragging columns from
one table to the other.
Table 11.1 outlines the four panes in the Graphical Query Designer.
CHAPTER 11 Accessing Data
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
187
Querying Data
11
Changing the diagram or grid affects the SQL and Result panes. For example, when you
add a table to the diagram, it actually adds a database table to the SQL query as it is being
generated. This is a good way for users to actually learn SQL. Figure 11.3 shows the
Graphical Query Designer.
Generic Query Designer
The Generic Query Designer is open ended. It is for times when you need more flexibility
than the Graphical Query Designer allows. This flexibility is especially helpful for running
multiple SQL statements to perform some preprocessing, or for writing dynamic statements
based on parameters or custom code. Figure 11.4 shows the Generic Query Designer.
Toolbar

Result pane
SQL pane
Grid pane
Diagram pane
Add table
Sort by selected column:
ascending/descending
Show/hide panes
Verify SQL
Run query
Toggle between graphical
and generic query designers
Generate GROUP BY
Remove filter/selected column
from a WHERE clause
FIGURE 11.3
Graphical Query Designer.
TABLE 11.1
Continued
Pane Function
Query Displays the Transact-SQL query represented by the Diagram and Grid panes. Use
this pane to write or update a query using T-SQL query language.
Result Displays the results of the query. To run the query, right-click in any pane, and then
click Run.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
188
CHAPTER 11 Accessing Data
FIGURE 11.4

Generic Query Designer.
NOTE
For both Graphical and Generic Query Designers, make sure to click the OK button
after you have completed query modifications. Just closing the Designer window will
cancel changes, and you might lose a valuable work.
Data Set Properties
The data set contains a couple of properties of which developers should be mindful. Those
properties are accessible through the Dataset Properties dialog box. To bring up the
Dataset Properties dialog box (see Figure 11.5), open the Report Data dockable window
(from the main BIDS screen, choose View, Report Data), right-click a data set, and select
Dataset Properties from the drop-down menu.
The properties are as follows:
. The
Name
of the data set
. The
Data source
or a pointer to a shared data source
. The
Query type
or a type of query for a data set:
Text
,
Table
, or
Stored Procedure
. The
Query
, which represents a query that retrieves data from the data source
From the Library of STEPHEN EISEMAN

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
189
Querying Data
11
FIGURE 11.5
Dataset Properties dialog box.
. The
Fields
collections, which includes fields retrieved by the query and calculated
fields
. The
Parameters
(a parameter in a query string, such as
SELECT * FROM
Person.Address WHERE City = @City
) and
Dataset
/
Parameters
, which are used to
limit selected data and must have matching parameters in each for proper report
processing
. The
Filters
collection, which further filters result of the query inside of a Report
Server after a data set returns data
. The
Options
, which provides instructions on how to execute a query (

Time out
) or
how to sort (collation, sensitivity) and interpret the subtotals
Query
is the only property available for access during runtime through the
CommandText
property of the
DataSets
collection. The rest of the properties are stored in Report
Definition Language (RDL) and used by SSRS to process a data set.
Command Type
The command type is similar to the ADO.NET command type. It indicates the type of
query that is contained in the query string and corresponding
CommandText
element of
RDL. There are three values:
Table
,
Text
, and
Stored Procedure
.
Text
provides for execu-
tion of a free-form (but, of course, valid) query.
Stored Procedure
corresponds to a stored
procedure call. Finally
Table
indicates for SSRS to use the

TableDirect
feature of SQL
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
190
CHAPTER 11 Accessing Data
Server, where the query is the name of a table from which to retrieve data. All data from
the table is returned.
NOTE
Not all the providers support all three values. For example, whereas OLE DB supports
the
Table
command type, the .NET provider Microsoft SQL Server (SqlClient) does not.
Therefore, Table is grayed out for the Microsoft SQL Server (SqlClient) provider. Of
course,
SELECT * FROM <Table>
would work just the same in the case of either
provider.
Parameters
Most queries and stored procedures require inputting some type of parameter to return
data. Consider the following example:
SELECT *
FROM Person.Address
WHERE (City = @City)
This is an example of a parameterized SQL on an
Address
table. Input parameters to stored
procedures are another good example. So how does the data set give us this functionality?
The answer is in the

Parameters
collection. To be clear, query parameters are separate
from report parameters. Query parameters are used during the processing of the query, or
SELECT
statement.
When you execute a query with a parameter in either of the designers, it will prompt you
to enter its value (see Figure 11.6).
If a query parameter is specified, a value must be given to the parameter for the query to
process. A report parameter is used during report processing to show different aspects of
the data that can include, but are not limited to, query processing. If a T-SQL query
includes query parameters, the parameters are created in a report automatically, and the
values specified in the report parameters are passed along to the query parameter.
The Report Designer automatically creates a report parameter with the same name as the
query parameter. If there is already a parameter with the same name, it associates the two
parameters. Figure 11.7 shows the association and where it is located in the user interface.
Note that when you click the fx button to expand
[@City]
you will see the following
expression:
=Parameters!City.Value
. This is exactly the mapping between
@City
query
parameter and report’s parameter
City
.
After the Report Designer creates a report parameter, you will have to remove it from the
set of report parameters manually. This is true even if you have removed the parameter
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

ptg
191
Querying Data
11
FIGURE 11.6
An example of how a designer prompts you for the parameters.
FIGURE 11.7
SQL and report parameter association.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
192
CHAPTER 11 Accessing Data
from a query. However, the Report Designer will remove the association if the parameter is
no longer present in the query.
Stored procedures can be executed by changing the command type to
Stored Procedure
and entering the SQL statement. There is no reason for the
EXEC
clause. If a stored proce-
dure has default values, that value can be passed through to the procedure by passing the
query parameter the keyword
DEFAULT
.
The
Timeout
property sets a limit as to the amount of time the query can run. If left
empty or set to
0
, the query can run indefinitely.

Querying XML
The ability to directly query XML as a data source became available in SSRS2K5. Because
querying XML is a little different from querying an RDBMS and fairly wide usage of XML,
it is worth noting some special requirements unique to using XML as a data source. They
are as follows:
. Set XML as the data source type.
. Use a connection string that points to either the URL of a web service, web-based
application, or XML document. XML documents from inside SQL Server cannot be
used. Instead, use
xquery
or
xpath
as a part of the query with SQL Server as the data
source type.
. Use either Windows integrated security or no credentials. No other type of creden-
tials is supported.
. The result of the query must be XML data.
. Define the XML query using either the element path, query element, or leave it empty.
The Generic Query Designer is the only way to create queries against XML. The Graphical
Query Designer will not work. The good news is that developers can specify one of three
types, as shown in Table 11.2.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
193
Querying Data
11
TABLE 11.2
XML Query Types
XML Query

Type
Description and Syntax
Element path The element path specifies the path to the data to return without including
namespaces.
Syntax:
ElementPath = XMLElementName [/ElementPath]
XMLElementName = [NamespacePrefix:]XMLLocalName
Query
element
The query element is similar to the element path, but it helps to define name-
spaces for the element path.
Syntax:
<Query
xmlns:es=” />Sales”>
<ElementPath>/Customers/Customer/Orders/Order/es:LineItems/es:Line
Item</ElementPath>
</Query>
Empty No query. It takes the first element path to a leaf node and applies it to the
whole document.
In the following document, an empty query will default to the following:
/Custs/Cust/Orders/Order:
<Custs>
<Cust ID=1>
<Name>Bob</Name>
<Orders>
<Order ID=1 Qty=6>Chair</Order>
<Order ID=2 Qty=1>Table</Order>
</Orders>
<Returns>
<Return ID=1 Qty=2>Chair</Order>

</Returns>
</Cust>
<Cust ID=2>
Name>Aaron</Name>
</Cust>
</Custs>
Fields
The result of processing the query is the
Fields
collection. When the Report Designer
processes a query you have entered in the Dataset Properties dialog box, the Report
Designer identifies fields returned by a query and populates the
Fields
collection. In the
majority of the cases the Report Designer identifies fields returned by a query automati-
cally as you either move to a different tab (like Fields) of the Dataset Properties dialog box
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
194
CHAPTER 11 Accessing Data
FIGURE 11.8
Adding a calculated field to a data set.
or click OK to complete it. If this did not happen, you can click the Refresh Fields button
to force the Report Designer to update the fields in the data set.
There are two types of fields. The first and most obvious is the database fields. Database
fields are the direct result of running the query. As you might have noticed, the field
name automatically gets set to the field name as expressed by the query.
The second type of field is a calculated field. This is the result of using expressions or
custom code to derive a value. An expression value can, but does not have to, be based on

one of the database fields. The value could just be a result of the function
Now()
.
Let’s examine a calculated field. Suppose you want to determine the percent of a quota a
salesperson has met.
You can add a calculated field to the data set and plug in this expression (see Figure 11.8):
=SalesYTD/SalesQuota * 100
Note that calculated expressions have
<<Expr>>
in the Field Source column and an fx
button after it.
A word of caution on calculated fields: The calculation is performed for every row brought
back from the data set. If it is a large data set, this can be rather time-consuming.
Fields and XML
In dealing with XML, every element along the element path and every attribute return as
a field. All the fields are
String
data types. Some fields even include embedded XML.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
195
Summary
11
Filters
At first, it might seem strange that you would need a filter at the data set level. After all,
why would you need them, if you can just modify the
WHERE
clause in the SQL? The
dilemma comes when you need to run canned queries, such as stored procedures, or if

you cannot pass in the appropriate value to filter inside the SQL.
A word of caution comes with this, too: It is much easier to filter at the database level than
at the client level. Returning large data sets simply to filter it down to one or two rows on
the Report Server is possible, but it might be an inefficient use of system resources.
Adding a Data Source
If you have closed the solution we have developed in the previous chapter, reopen it. To
create a data source, complete the following steps:
1. From Solution Explorer, right-click the project name.
2. From the drop-down menu, select Add, New Item.
3. In the Project Items list box that appears, select Data Source.
4. For the name, enter
AdventureWorks
.
5. Select Microsoft SQL Server.
6. Enter the following connection string:
Data Source=(localhost);Initial Catalog=AdventureWorks
7. On the Credentials tab, select the Use This User Name and Password option and
enter the username and password. This option allows the report to run unattended
with the database credentials that you specified. The credentials will be encrypted
and stored in the ReportServer database. If instead of database credentials you want
to store Windows credentials, you can publish the data source, and edit it on the
target server using Report Manager. Using Report Manager, specify the username and
password in the format
<domain>\<account>
, and then select Use as Windows
Credentials When Connecting to the Data Source.
8. Click OK (or click Apply if you used Report Manager to edit the data source).
Summary
Data sources provide the report with a connection to the data. Data sets use the data
source along with a query of some kind to produce a resultset that the rendering engine

takes and uses to process the report.
Data sources can be either specific to a report or shared among many reports. A number of
data providers are installed with SQL Server and include SQL Server, SSAS, Oracle, XML,
Teradata, SAP, and Essbase.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
196
CHAPTER 11 Accessing Data
Many other data sources are supported through .NET, OLE DB, and ODBC. If a provider is
not available, it can be custom developed. It is helpful from an administration point of
view to use a shared data source whenever possible. An exception to this is when a data
source needs specific credentials or elevated security.
Visual Studio offers two query designers: the Graphical Query Designer and the Generic
Query Designer. SSRS leaves the processing of the query to the data source. After the data
source is finished processing the data, it generates a data set, which is a collection of fields
inside of rows.
Calculated fields can be added to the data set at design time to augment the returned
results. Filters can also be applied to the resulting data sets. Both filters and fields are
applied on a row-by-row basis and, if not used carefully, can lead to performance problems.
Parameters can either be static or bound to data sets. The value of certain parameters can
also be passed in as input to a query. The output of that query can be used as the list of
values for a parameter, in effect creating a dependency between parameters and data sets.
This dependency can be used in many different ways to affect the data used in the final
data set processed.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
CHAPTER
12

Report Parameters
IN THIS CHAPTER
. Setting Up Parameters
. Parameter Properties
. Data-Driven Parameters
. Expressions with Parameters
. Dynamic SQL with Parameters
. Parameter Dependencies
. Using Multivalue Parameters
. Example of Using Multivalue
Dependent Parameters
R
eport-level parameters can serve a number of functions,
including the following:
. Manipulating report data
. Connecting related reports together
. Varying report layout and presentation
Parameters are used to pass information to a report to influ-
ence report processing. For example, a parameter can serve
as a condition in a
WHERE
clause of a query that generates
the report’s data set. Parameters are relatively easy to set up
and are very flexible.
Report parameters can be presented to the user in several
ways, as shown in Table 12.1. Note that you as a report
designer have control over the user’s entry, but only if you
specify available values for a parameter. If you specify both
available values and default values, then
. When SSRS finds a match between available and

default values, SSRS would present a parameter selec-
tion control (see Table 12.1) with default values pre-
selected from a list of available values. For example, if
you specify Value1 and Value2 as available and
specify Value2 as default, SSRS would display
Multiselect list as the parameter selection control and
Value2 will be selected.
. Otherwise, default values are ignored.
When you specify the default values but not available
values, SSRS would present a corresponding control with
default values entered. The default values can be overrid-
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
198
CHAPTER 12 Report Parameters
TABLE 12.1
Parameter Presentation Options
Control Number of
Values
Report Designer Has
Control Over Entered
Values
Presented When
Text box 1 No. Single-value parameter,
excluding
Boolean
and
DateTime
types.

Multiline text box 1-N No. Multivalue parameter
with no available values
specified. If a designer
specifies default values,
they will be presented,
but can be overridden.
Text box with calendar
control
1 No.
DateTime
type single-
value parameter.
Drop-down list 1 Yes. Single-value parameter
with multiple available
values.
Multiselect list 1-N Yes. Multivalue parameter
with multiple available
values.
Check box titled NULL 1 N/A. Restricted to
checked/unchecked
state.
Presented when
designer checks Allow
Null Value option.
Toggle-able radio button 1
N/A. Restricted to
True
or
False
selections.

Single-value
Boolean
parameters only.
den. For example, if you specify Value2 as default and do not specify any available values,
SSRS would display a Text box (or Multiline text box if it is a Multivalue parameter) with
Value2 entered. You would be able to override Value2 with another value.
Parameters can also be hidden from the user. Although this might sound strange at first,
hidden parameters can be used to alter report processing based on the input from other
parameters, or based on the result from a data set.
Setting Up Parameters
You can set up parameters from the Report Designer through the following steps:
1. Select View, Report Data from the BIDS main menu. This will open Report Data
dockable window.
2. In the Report Data dockable window, right-click the Parameters folder and select Add
Parameter from the drop-down menu. The initial screen looks similar to Figure 12.1.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
199
Parameter Properties
FIGURE 12.1
Report parameters.
12
Note the tabs General (shown on the figure), Available Values (allows you to enter a list of
available values), Default Values (allows you to enter a list of default values), and
Advanced. The Advanced tab controls how SSRS refreshes default values for dependent
parameters:
. Automatically Determine When to Refresh (default): Asks SSRS to analyze
dependencies and refresh when dependencies exist
. Always Refresh: Asks SSRS to always refresh, regardless of dependencies

. Never Refresh: Asks SSRS to never refresh
Parameter Properties
Table 12.2 outlines several properties of parameters.
TABLE 12.2
Parameter Properties
Property Name Expected Value Description
Name String
The actual and unique name of the parameter
within the scope of the report. This is what the
parameter is referred to when referencing it in the
Globals
collection.
From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ptg
200
CHAPTER 12 Report Parameters
Later on in the chapter, you will walk through creating report parameters.
Data-Driven Parameters
Report parameter values can be driven from a list of valid values. This list can come from
a data set. Under Available Values, just add a list of values for the values to remain hard-
coded in the RDL. If you want to drive them from a data source, select Get Values from a
TABLE 12.2
Continued
Property Name Expected Value Description
Data type Enum
:
Text
(default),
Integer

,
Date/Time
,
Boolean
,
Float
The data type in which to expect the parameter. It
defaults to
String
, but you can choose a different
data type from the drop-down list. If the report
parameter values come from a query, the return
type for the query must match the type specified
here. Because .NET CLR is a strongly typed
system, SSRS is too. It returns an error if a string
is passed in for what is supposed to be a number
value. For a
Boolean
value, the Report Server
simply creates a radio button list with
true
/
false
as the only options.
Prompt String
A friendly message to pass to the user who enters
the parameter data. If it is left empty, and a default
value is specified for the parameter, the user is not
asked to input the value because the report will
use the defaulted value. If the prompt is empty,

and no default value is specified, the report will
not run.
Allow blank value
(empty string,
””
)
Boolean
An empty string is a valid value.
Allow null value
Boolean
A parameter that can have a null value. SSRS
presents a check box with the title NULL. When
checked, a data entry control for the parameter is
grayed out.
Allow multiple
values
(
MultiValue
)
Boolean
Allows you to select multiple values by checking
check boxes in a drop-down list, instead of display-
ing a single text box or drop-down list.
Hidden Boolean
The value of this should not appear in the report,
but it can still be set at runtime.
Internal Boolean
A parameter that cannot be changed at runtime. A
consumer of a published report will never see this
as a parameter.

From the Library of STEPHEN EISEMAN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

×