Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Reference » SQL Data Types » Data type conversions » Comparisons between data types

Substitution characters Next Page

Comparisons between CHAR and NCHAR


When a comparison is performed between a CHAR type (CHAR, VARCHAR, LONG VARCHAR) and an NCHAR type (NCHAR, NVARCHAR, LONG NVARCHAR), SQL Anywhere uses inference rules to determine whether the NCHAR value can, and should, be coerced to the CHAR type. A value can be coerced if it is a literal constant, a variable, a host variable, or a complex expression not based on a column reference. Generally, when an NCHAR value is compared to a CHAR column, the comparison is performed as CHAR if the NCHAR value can be coerced to CHAR; otherwise, it is performed as NCHAR.

Following are the inference rules, in the order in which they are applied:

Examples

The condition Employees.GivenName = N'Susan' compares a CHAR column (Employees.GivenName) to the literal N'Susan'. The value N'Susan' is coerced to CHAR, and the comparison is performed as if it had been written as:

Employees.GivenName  = CAST( N'Susan' AS CHAR )

Alternatively, the condition Employees.GivenName = T.nchar_column would find that the value T.nchar_column can not be coerced to CHAR. The comparison would be performed as if it were written as follows, and an index on Employees.GivenName can not be used:

CAST( Employees.GivenName AS NCHAR ) = T.nchar_column
See also