Datatype conversion functions change expressions from one datatype to another and specify new display formats for date and time information. The datatype conversion functions are:
You can use the datatype conversion functions in the select list, in the where clause, and anywhere else an expression is allowed.
Adaptive Server performs certain datatype conversions automatically. These are called implicit conversions. For example, if you compare a char expression and a datetime expression, or a smallint expression and an int expression, or char expressions of different lengths, Adaptive Server automatically converts one datatype to another.
You must request other datatype conversions explicitly, using one of the built-in datatype conversion functions. For example, before concatenating numeric expressions, you must convert them to character expressions.
Adaptive Server does not allow you to convert certain datatypes to certain other datatypes, either implicitly or explicitly. For example, you cannot convert the following:
smallint data to datetime
datetime data to smallint
binary or varbinary data to smalldatetime or datetime data
Unsupported conversions result in error messages.
Figure 2-3 indicates whether individual datatype conversions are performed implicitly, explicitly, or are not supported.
Figure 2-3: Explicit, implicit, and unsupported datatype conversions.
E – explicit datatype conversion is required.
I – conversion can be done either implicitly, or with an explicit datatype conversion function.
I/E – Explicit datatype conversion function required when there is loss of precision or scale, and arithabortnumeric_truncation is on; implicit conversion allowed otherwise.
U – unsupported conversion.
– conversion of a datatype to itself. These conversions are allowed, but are meaningless.