CONVERT#
Converts a value from one data type to another. CONVERT is the SQL Server–specific conversion
function and additionally accepts a style that controls how dates, times and numbers are formatted.
Syntax#
CONVERT ( data_type [ ( length ) ], expression [ , style ] )
Examples#
SELECT CONVERT(date, '2017-05-04');
SELECT CONVERT(varchar(20), GETDATE(), 120);
Float and real styles#
Converting float or real to a character type produces the same text as SQL Server. This also applies
to CAST and to implicit conversions, for example the value side of LIKE or string concatenation.
Style |
Output |
Example for |
|---|---|---|
0 (default) |
At most 6 significant digits; scientific notation for very small or very large values |
|
1 |
Always scientific notation, 8 significant digits |
|
2 |
Always scientific notation, 16 significant digits |
|
3 |
Always scientific notation, 17 significant digits |
|
Style 126 behaves as style 2 for float and as style 1 for real. See the
SQL Server CAST and CONVERT reference
for details.
Note
Style 129 is not supported for float and real and is treated as style 0. In rare cases the last
digit of style 3 differs from SQL Server by one. See Feature support.