Collections:
CONVERT() - Converting Character Strings to Numeric Values in SQL Server
How To Convert Character Strings into Numeric Values in SQL Server Transact-SQL?
✍: FYIcenter.com
Sometimes you need to convert numeric values enclosed in character strings back to numeric values by using the CONVERT() function.
When converting character strings to values with CONVERT(), you need to remember two rules:
The tutorial exercise below shows you how to use the CONVERT() function to convert strings to values:
SELECT CONVERT(NUMERIC(10,5), ' 12345.12 '); GO 12345.12000 -- Input does not match the target data type SELECT CONVERT(INT, '12345.12'); GO Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '12345.12' to data type int. -- Input does not match the target data type SELECT CONVERT(NUMERIC(10,5), '12345.12E+00'); GO Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to numeric. -- Double conversion works SELECT CONVERT(NUMERIC(10,5), CONVERT(FLOAT(24), ' 12345.12E+00 ')); GO 12345.12012 SELECT CONVERT(FLOAT(24), ' 12345.12E+00 '); GO 12345.12
⇒ Overflow Errors on Converting Big Values to Integers in SQL Server
⇐ CONVERT() - Converting Numeric Expression Data Types in SQL Server
⇑ Numeric Expressions and Functions in SQL Server Transact-SQL
2017-03-22, 3280🔥, 0💬
Popular Posts:
How To Convert Numeric Values to Integers in SQL Server Transact-SQL? Sometimes you need to round a ...
How To Convert Numeric Values to Character Strings in MySQL? You can convert numeric values to chara...
How To Provide Default Values to Function Parameters in SQL Server Transact-SQL? If you add a parame...
How To Drop an Index in Oracle? If you don't need an existing index any more, you should delete it w...
Where to find answers to frequently asked questions on CREATE, ALTER and DROP Statements in MySQL? H...