|
cast()
The
Datatype Conversion Function
cast()
converts a given value of a
datatype
into another datatype. The function cast() can also change the
nullability
of the parameter "expression".
Furthermore, cast() returns the default format for a given date and time value.
The function cast() is available in
ASE®
starting with version 12.5.
Syntax of the Datatype Conversion Function cast()
cast(expression as datatype [(length | precision[, scale])])
Parameters of the Datatype Conversion Function cast()
expression
The parameter "expression" contains the value of an arbitrary
datatype
to be converted.
The parameter should be set between double quotes. It can contain column names,
constants,
Functions
as well as any combination of constants and functions which can be linked with arithmetic or bitwise
operators
or
subqueries.
If Java
is active in the current
Datenbank
the parameter "expression" can be converted into a Java-SQL class.
When converting a datatype into
unichar
the default length is 30, if the parameter "length" has not been given.
length
The parameter "length" is an optional placeholder for a datatype specific length.
If the datatype can take a length option, this can be added in parentheses, e.g. varchar(255).
The parameter can be used with the datatypes
char,
nchar,
unichar,
univarchar,
varchar,
nvarchar,
binary
and
varbinary
. If length is not given, all characters or
bytes
after the 30th will be ignored and cut off without warning.
The maximum length for characters and bytes is 64K.
precision
The parameter "precision" is equal to the number of digits for the datatypes
numeric
or
decimal.
For the datatype
float
the parameter "precision" describes the number of binary digits in its mantissa,
i.e. the number of logarithms behind the decimal point.
If the parameter "precision" has not been given a value,
ASE will use the default precision of 18 for numeric and decimal datatypes.
scale
The parameter "scale" describes the number of digits on the right side
of the decimal point of a decimal value. The parameter "scale" is optional.
If it is not set the default value of "0" is used.
Example for the Datatype Conversion Function cast()
select cast( as datetime)
go
-----
Returns the date in default format.
See also:
inttohex(),
biginttohex(),
bintostr(),
hextoint(),
hextobigint(),
convert(),
strtobin()
and
Functions.
See also:
ASE T-SQL - Aggregate Functions, biginttohex(), bintostr(), convert(), Datatype Conversion Functions, explicit conversion, hextobigint(), hextoint(), implicit conversions, inttohex().
|