With expressions, we are talking about the Microsoft SQL Server Reporting Server expressions that we can use from either the Visual Studio Report editor or with the SQL Report Builder tool.
The basic expressions are grouped in the following categories:
Constants
Built-in fields
Parameters
Fields
Datasets
Variables
Operators
Arithmetic ( ^, *, /, \, Mod, +, -)
Comparison ( <, <=, >, >=, =, <>, Like, Is)
Concatenation ( &, +)
Logical bitwise ( And, Not, Or, AndAlso, OrElse)
Bit Shift (<<, >>)
Common Functions
Text
Date and Time
Math
Inspection
Program Flow
Aggregate
Financial
Conversion
Miscellaneous
The basic expressions are available in the Expression editor dialog box, as shown in the following screenshot:
The Constants option will show you all the constants you have defined for your report. Constants are useful if you want to avoid using values in your expressions that would not make sense in a big piece of code. For example, asking if a variable such as status equals zero is not the same as saying the variable status equals active. In that case, creating a constant for the active value would be defined as follows:
Public Const Active As Int32 = 0
You can define constants in the Code section. You can access the Code section by going to the Report | Report Properties menu in Visual Studio.
A custom code for this report is as follows:
Public Const MyConstantStr = "Damian" Public Const MyConstantInt As Int32 = 1
Notice that these constants might not be displayed in the Constants category, but you can still use them in the Expression editor as follows:
For example, the expression set for ToolTip is as follows:
= Code.MyConstantStr
You can define global variables in the Variables section, which you can access by going to the Report | Report Properties menu in Visual Studio. Variables can be read only; in that case, they will be similar to constants and they can also contain expressions.
You can then use the variables as follows:
= Variables!myVar.Value