关于 Reporting Services 的实用技巧
关于使用 Reporting Services 的一些实用技巧。
引言
在使用 Reporting Services 的过程中,我发现了一些小技巧,想和大家分享。可以将其视为使用 Reporting Services 的技巧。
参数表示
当我们编写存储过程时,肯定需要定义参数。如果使用的是 SQL Server,这不成问题。我们可以使用符号 ‘@’ 和参数名来执行此操作。如果使用 ‘Oracle 数据库’ 作为后端,则需要使用符号 ‘:’ 和参数名。
保留报告中的空格
在我们的报告中,有时我们希望保留空格,这意味着如果我们文本框中放置了一些空格,然后是文本。当渲染报告时,报告渲染引擎会忽略这些空格。为了确保报告渲染引擎不忽略这些空格,我们需要插入 alt+0160(即按住该键并输入 0160),而不是按空格键。
为多值参数添加空值
当我们使用多值参数时,我们希望将空值作为选项,因为我们可能希望默认选中它。问题是,多值参数没有空值。一种可能的解决方案是创建一个包含空值的视图。为此,我们可以使用 SQL 中的 UNION ALL 命令。
示例
CREATE VIEW viewDomainWithNull
AS
SELECT -1 AS [Domain Id],'NULL' AS [Domain Name]
UNION ALL
SELECT [Domain Id],[Domain Name] FROM Domain
For the default value in the parameter dialog box, we can enter the value ‘-1’.
This would make null be selected by default.
在报告中使用交替行颜色
要为行提供交替颜色,我们可以使用“IIF”语句。首先选择必须具有交替颜色的数据行,然后选择背景颜色选项的表达式。
The general syntax is as follows
=IIF( RowNumber(“datasource name”) Mod 2,"color1”,"color2")
RowNumber returns the number of rows.
Color1 if the mod expression returns true
Color2 if the mod expression returns false
This will give two colors alternating for the data rows.
The same expression can be extended to allow more colors to be used.
=IIF( RowNumber(“datasource name”) Mod 3 = 0,"color1”,
IIF(RowNumber(“datasource name”) Mod 3 = 1,"color2",”color3”))
这将为数据行提供三种交替颜色。
将外部图像添加为背景图像
在设置“文本框”的背景图像时,我们可以使用嵌入式图像,但如果我们不想使用它怎么办。假设我们在报告项目文件夹中有一个可以使用的图像。在 背景 图像选项下,对于 值 字段,输入文件名。
如果有一个名为“test.gif”的文件,则将其输入到值字段中。