The syntax of the Crystal Reports formula is relatively simple, but many operators and functions are supported.
The following describes fields, operators, and functions.
I. Fields
Many fields used when creating a report can also be referenced in the formula. For example, fields such as database, parameter, run total, SQL expression, abstract, and group name can be used in formulas. You can also reference other formula fields in the formula.
To insert fields to a report, double-click the field name in the report field tree. This ensures that the correct field is used.
Syntax.
Names of fields such as databases, parameters, formulas, run totals, and SQL expressions are enclosed in curly brackets.
The database field name is taken from the database: {employee. Surname}
Specify the names of parameters, formulas, run totals, SQL expressions, and other fields when creating a field.
The parameter field also contains a question mark :{? My parameter fields}
The formula field contains one @ Symbol: {@ another formula}
The run sum field contains a # symbol: {# my run total}
The SQL expression field contains a percent sign: {% My SQL expression}
The summary and group name sections look like function calls. However, they are actually shorthand for report fields.
Sum summary field: Sum ({Order. Order amount}, {order. Carrier })
Group name segment: GroupName ({order. Carrier })
Ii. Operators
Crystal Reports supports many operators, some of which are common and some are unique to Crystal Reports.
1. Arithmetic Operators
Crystal Reports supports the +,-, *,/, and % (percentage) operators, such as 100% 500 = 20.
2. Conversion Operators
The conversion operator $ converts a number to a currency type, so that Crystal Reports prints data according to the currency format in the report.
3. Comparison Operators
Crystal Reports supports the same comparison operators as Visual Basic: =, <>, <,>, >=, and <=.
4. String Operators
The operator for string connection is "+ ".
Use the [] operator to take the specified character from the string, which is equivalent to the Mid function of Visual Basic. "[]" Is a word
The first character is 1. For example: {file. ItemNumber} [4 to 5]
Determines whether a string is included in another string using the in operator. For example, "c" in "pcc" returns True.
5. Range Operators
Crystal Reports allows users to establish a range and determine whether data is included in the specified range. For example, "100.00 to 250.00" contains data between 100 and 250, and "50 in (100 to 250)" can be used to determine whether 50 is within the specified range.
6. boolean operators
Boolean operators include And, Not, And Or.
7. array Operators
Crystal Reports supports arrays. For example, [100,200,300,400] is an array composed of four elements. You can use the in operator to determine whether the data is an array element, for example, {file. State} in ["CA", "HI", "AK"].
8. Matching Operators
The matching operators include StartsWith and Like. StartsWith checks whether a string starts with a specified string. For example, "PCC" startwith "P" returns True. Similar to Visual Basic, the Like operator also uses string expressions and
Compare the styles in the character expression.
9. Other operators
Another important operator is If... Then... Else ..., It is the condition judgment we are familiar.
For example, we can see the power of this operator.
To assign a value to a variable, use the ": =" symbol, which is different from Visual Basic.
You can also add comments to the formula to facilitate reading. The comment symbol is "//", and the content after the symbol "//" will be ignored
.
The formula can also contain multiple statement rows, which are separated by ";" at the end of the row.
Iii. Functions
Crystal Reports supports a large number of functions, including mathematical functions, statistical functions, date functions, string functions, and array functions. The Help File of Crystal Reports provides a detailed description of each function.