Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.

Email this linkEmail this link Printer-Friendly VersionPrinter-Friendly Version Bookmark and ShareShare
Field codes: Compare field
 

{ COMPARE Expression1 Operator Expression2 }

Compares two values and displays the result "1" if the comparison is true or "0" (zero) if the comparison is false. You can use this field to create compound logical comparisons with AND and OR functions in an = (Formula) field, and then you can use the result of the = (Formula) field in an IF field.

ShowInstructions

Expression1, Expression2

Values to compare. Expressions (expression: Any combination of mathematical or logical operators, constants, functions, and names of fields, controls, and properties that evaluates to a single value. Expressions can perform calculations, manipulate characters, or test data.) can be bookmark (bookmark: A location or selection of text in a file that you name for reference purposes. Bookmarks identify a location within your file that you can later refer or link to.) names, strings of text, numbers, nested fields that return a value, or mathematical formulas. If an expression contains spaces, enclose the expression in quotation marks.

Operator

Comparison operator (operator: A sign or symbol that specifies the type of calculation to perform within an expression. There are mathematical, comparison, logical, and reference operators.). Insert a space both before and after the operator.

Operator Description
= Equal to
<> Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

 Note   If the operator is = or <>, Expression2 can contain a question mark (?) to represent any single character, or an asterisk (*) to represent any string of characters. The expression must be enclosed in quotation marks so that it is compared as a character string. If you use an asterisk in Expression2, the portion of Expression1 that corresponds to the asterisk, plus any remaining characters in Expression2, cannot exceed 128 characters.

ShowExamples

Suppose that the IF field in the following example is inserted into a mail merge main document. The COMPARE fields examine the data fields (data field: A category of information that corresponds to one column of information in a data source. The name of each data field is listed in the first row (header row) of the data source. "PostalCode" and "LastName" are examples of data field names.) CustomerNumber and CustomerRating as each data record (data record: A complete set of related information that corresponds to one row of information in the data source. All information about one client in a client mailing list is an example of a data record.) is merged. The OR function of the = (Formula) field returns the value "1" (true) if at least one of the data fields indicates poor credit, in which case the first text in quotation marks is printed.

{ IF { = OR ( { COMPARE { MERGEFIELD CustomerNumber } >= 4 }, { COMPARE { MERGEFIELD CustomerRating } <= 9 } ) } = 1 "Credit not acceptable" "Credit acceptable"}

The following COMPARE field results in the value "1" if any value in the PostalCode data field is the range 98500 – 98599:

{ COMPARE " { MERGEFIELD PostalCode } " = "985*" }

© 2009 Microsoft Corporation. All rights reserved.