Skip to Content

mvSQL Database Function - CAST()

Summary

Converts an expression to another data type.

Syntax

CAST(<expression> as <datatype>)

Parameters

expression

A valid sql expression, or reference to a column.

datatype

A valid sql datatype. Supported datatypes include:

  • char(length) (Ex: char(12))
  • nvarchar(length) (Ex: nvarchar(123))
  • numeric(precision,scale) (Ex: numeric(10,1))

Not recommended:

date datetime time timestamp

Returns

expression cast as appropriate data type

Remarks

Note that some databases do not support casting to some datatypes. mvSQL will substitute database-specific types where required. For example, MySql does not natively support: CAST(123 as nvarchar(4)) - this expression gets mapped to CAST(123 as char(4)).

Examples

  1. 'EmployeeId' || CAST("Employee"."EmployeeId" as nvarchar(100)) Returns EmployeeId123

  2. CAST('123.5' as numeric(10,1)) Returns 123.5