Expression Syntax


Expressions are preceded by an "=" sign, which tells the report-processing engine that the statement following this sign has to be evaluated. It is certainly possible to turn even a constant to an expression. For example, the VerticalAlign property can have constant values: Top , Middle , and Bottom , or, alternatively, a developer can express those constants as expressions ="Top" , ="Middle" , or ="Bottom" .

If you are more familiar with Microsoft Excel than VB.NET, expressions are similar to VBA expressions in Excel. Starting an expression with an "=" sign only increases the resemblance.

Expressions can be used to achieve several goals: display the values on a report and calculate values for style and formatting properties.

Style change can include variation of colors, highlights, and shapes of displayed data. To accomplish those goals, expressions are used in properties of reporting items. Most properties of the reporting items support expressions, and few (such as Name ) do not. Most of the expressions in properties are strings, few are VBA constants, such as true or False , and a few have numeric values.

Let's start our examination by taking a look at a simple yet common expression:

 =Fields!FirstName.Value 

This is a common expression for retrieving values from a data set. As expected, the expression starts with an equal sign. Next is the keyword " Fields ." This is in reference to the Fields collection of the parent data set. The next piece ( !FirstName.Value ) makes reference to the FirstName field in the Fields collections, and gets its value. It is also possible to use functions around fields to achieve a desired result. For example:

 =Sum(Fields!Price.Value) 

Expressions can contain one or more of the following:

  • Constants Constants can be static expressions, (such as static text ="Text" or numeric =5 ) or predefined (such as color , text alignment, and font family). Most of the properties accept predefined constants. For example, TextAlign can have one of the following values: General , Left , Center , and Right .

  • Collections Items of all collections are read-only . The item can belong to one of the following collections:

    • Parameters (see Chapter 10, "Report Parameters," for a Parameters collection discussion)

    • Fields

    • Data sets

    • Report items

    • Users

    • Globals

  • Operators Operators include the programmatic symbols used for common mathematical operations such as addition, subtraction, power, modulo, and so on, as well as operations on strings such as string concatenation.

    • Arithmetic operators include ^, *, /, \, Mod, +, and-.

    • Comparison operators include < , > , <= , >= , = , <> , Like ( compares two strings), and Is (compares two object reference variables ).

    • Concatenation operators include & and + . Use the & operator for concatenation of two strings to avoid confusion with adding two numbers .

    • Logical/Bitwise operators include And , Not , Or , Xor (logical exclusion operation), AndAlso ( performs short-circuiting logical conjunction on two expressions), and OrElse (short-circuiting logical disjunction on two expressions).

    • Bit Shift operators include << and >>.

  • Visual Basic runtime functions Keep in mind that the Expression Editor will provide only the most common functions from the VB runtime library such as Right, Left, InStr, Format, and so on.

  • Custom functions See Chapter 22, "Implementing Custom Embedded Functions," for more details.

Tip

If you use an expression for the value of a property and you either receive an error or are not able to achieve the desired result (for example, text alignment does not work properly), you need to make sure that the type of the expression value is appropriate for the property. For example, if you use the following expression for the VerticalAlign property =IIF(1=1, Top, Bottom) , SSRS returns a runtime error: The VerticalAlign expression for the text box '<textbox name>' contains an error: [BC30451] Name 'Top' is not declared.


The proper expression is: =IIF(1=1,"Top","Bottom") .

Alternatively, if you enter =IIF(1=1,10,0) in the BorderWidth property, there is no runtime error, and SSRS is not going to provide an expected width, because the property expects a string ( "10pt" ) as opposed to a numeric value.



Microsoft SQL Server 2005 Reporting Services
Microsoft SQL Server 2005 Reporting Services
ISBN: 0672327996
EAN: 2147483647
Year: 2004
Pages: 254

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net