The convert function allows you to change the type of an expression.
The syntax is
CONVERT(expression, 'type-name'[, 'mode'])
The type name should in general be in lower case.
This can be useful in a number of situations. Some cases where you might want to use convert are
SELECT convert(id, 'date')
FROM LOG;
Caveat: Note that in Texis version 7 and later, convert()
ing
data from/to varbyte
/varchar
no longer converts the data
to/from hexadecimal by default (as was done in earlier versions) in
programs other than tsql
; it is now preserved as-is (though
truncated at nul for varchar
). See the bintohex()
and
hextobin()
functions (here) for
hexadecimal conversion, and the hexifybytes
SQL property
(here) for controlling automatic hex
conversion.
Also in Texis version 7 and later, an optional third argument may be
given to convert()
, which is a varchartostrlstsep
mode
value (here). This third argument may
only be supplied when converting to type strlst
or
varstrlst
. It allows the separator character or mode to be
conveniently specified locally to the conversion, instead of having to
alter the global varchartostrlstsep
mode.