How to use convert function
How to use the convert function? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
The CONVERT function is used to convert numbers from one measurement system to another. Its syntax is "CONVERT (number,from_unit,to_unit)"; three parameters in turn represent: the numerical value that needs to be converted in units of "from_units"; the unit of the numerical value; and 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 is the number that needs to be converted in from_units.
From_unit is the unit of numeric number.
To_unit is the unit of the result.
The convert function is used to convert data types
Example:
SELECT CONVERT (VARCHAR (5), 12345)
Return: string '12345'
Other uses
When used with datetime, smalldatetime, or sql_variant data types
CONVERT and CAST provide similar functionality: explicitly converting an expression of one data type to another.
Grammar
Use CAST:
CAST (expression AS data_type)
Use CONVERT:
CONVERT (data_type [(length)], expression [, style])
Parameters.
Expression
Is any valid Microsoft SQL Server ™expression. For more information, see expressions.
Data_type
The data types provided by the target system, including bigint and Sql_variant. User-defined data types cannot be used. For more information about available data types, see data types.
Length
Optional parameters of the nchar, nvarchar, char, varchar, binary, or varbinary data type.
Style
Date format style to convert datetime or smalldatetime data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types), or string format styles to convert float, real, money, or smallmoney data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types).
After reading the above, have you mastered how to use the convert function? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!