The information in this article applies to:
SUMMARYWhen the logical operator "=" (equal to) is used for character string comparisons, the results may not be exactly as expected. If two strings being compared are of different lengths, the outcome varies depending on the ON/OFF states of two environment settings: (1) SET EXACT specifies the rules Visual FoxPro uses when comparing two strings of different lengths in a non-SQL query environment; (2) SET ANSI determines whether the shorter of two strings is padded with blanks when a SQL-string comparison is made. Although these two environment settings have subtly different effects on the = operator, their distinctions in functionality are often misunderstood by developers because they both affect the comparison outcome of two strings of different lengths. MORE INFORMATIONThe = operator is often used in Visual FoxPro to perform character string comparisons. When two strings of different lengths are compared, the results may vary depending on the ON/OFF states of two environment settings such as SET EXACT and SET ANSI. In contrast, neither setting has an effect if both strings are of the same length. SET EXACT ON | OFFSET EXACT determines the rules Visual FoxPro uses when comparing two strings of different lengths in a non-SQL query environment. The ON state specifies that the shorter of the two expressions is first padded on the right with blanks to match the length of the longer expression, and then the two expressions are matched character-for-character to be equivalent. In contrast, the default OFF state concludes that two expressions are equivalent if the expression on the left side is matched character-for- character until the end of the expression on the right side is reached.It is important to emphasize that the left-to-right order of the two strings in a comparison is RELEVANT. Switching a string from one side of the = operator to the other affects the result of the comparison. Furthermore, the ON/OFF states of the setting's SET ANSI has no effect in comparing two strings of different lengths in a non-SQL query environment. The following examples further illustrate the point:
SET EXACT is scoped to the current data session.
SET ANSI ON | OFFSET ANSI specifies how comparisons between strings of different lengths are made with the = operator in SQL Commands. When the setting is ON, Visual FoxPro first pads the shorter expression on the right with blanks to match the length of the longer expression. The two strings are then compared character-for-character for their entire lengths to be equivalent. However, when the setting is OFF, the shorter expression is not padded with blanks. The two strings are simply compared character-for-character until the end of the shorter string is reached.Visual FoxPro builds a SELECT - SQL Command in the Query Designer when you create a query. If you choose the Equal option when creating join and filter conditions, the = operator is included in the generated SELECT. The SET ANSI setting can effect the results of queries you create and perform in the Query Designer, whereas the state of SET EXACT has no effect on the outcome of SQL string comparisons. In SQL commands, the left-to-right order of the two strings in a comparison is IRREVELANT. Switching a string from one side of the = operator to the other does not effect the result of the comparison. The following example demonstrates the precise effect of SET ANSI setting:
Additional query words: VFoxWin FoxWin
Keywords : FxprgSet |
Last Reviewed: December 14, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |