Home >Common Problem >How to use convert function?
The CONVERT function is used to convert numbers from one measurement system to another. The syntax is "CONVERT(number, from_unit, to_unit)"; the three parameters represent in turn: the value to be converted in "from_units"; the unit of the value; the unit of the result.
The CONVERT function is a function that converts numbers from one measurement system to another.
Syntax: CONVERT(number, from_unit, to_unit)
Parameters:
Number needs to be converted in units of from_units numerical value.
From_unit is the unit of the numerical number.
To_unit is the unit of the result.
convert function is used to convert data types
Example:
SELECT CONVERT (VARCHAR(5),12345)
Return: String '12345'
Other usage
With When the three data types of datetime, smalldatetime or sql_variant are used together,
CONVERT and CAST provide similar functions: explicitly converting an expression of a certain data type to another data type.
Syntax
Use CAST:
CAST ( expression AS data_type )
Use CONVERT:
CONVERT (data_type[(length)], expression [, style])
Parameters
expression
is any valid Microsoft SQL Server™ expression. See Expressions for more information.
data_type
Data types provided by the target system, including bigint and Sql_variant. User-defined data types cannot be used. For more information about the available data types, see Data Types.
length
Optional parameter for nchar, nvarchar, char, varchar, binary, or varbinary data type.
style
A date format style, used to convert datetime or smalldatetime data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types); or a string format style, used to convert Convert float, real, money, or smallmoney data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data type).
For more related knowledge, please visit PHP Chinese website! !
The above is the detailed content of How to use convert function?. For more information, please follow other related articles on the PHP Chinese website!