Conversion Functions in Expressions
Conversion functions convert expressions of one data type to another data type when data type conversions are not automatically performed by SQL Server.
You can find these formats at the following Microsoft websites:
- Predefined numeric formats: http://msdn.microsoft.com/en-us/library/y006s0cz.aspx
- User-defined numeric formats: http://msdn.microsoft.com/en-us/library/4fb56f4y.aspx
- Predefined date/time formats: http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
- User-defined date/time formats: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
Conversion
The following information describes the functions available for building expressions.
Function | Syntax | Description | Example |
---|---|---|---|
Trunc | TRUNC(number) | Calculates the integral part of a number. | TRUNC(3.67) = 3 |
ToDouble | ToDouble(number) | Converts a number or string to a double. | "4.5" = 4.5 |
ToDecimal | ToDecimal(number) | Converts a number or string to a decimal. | "4.5" = 4.5 |
ToString | ToString(object) | Converts a value to a string. A null value becomes "NULL." | ToString(4.5) = "4.5" |
Format | FORMAT(number, style) | Converts a number or date to a string formatted according to instructions contained in a format string expression. Returns a string value. | FORMAT(4.5, "E") = "4.500000E+000" |