T-SQL Tutorial

How to convert String to Numeric


To convert a String to Numeric uses sql conversion functions like cast or convert.

Syntax

CAST ( expression AS datatype [ ( length ) ] )

CONVERT ( datatype [ ( length ) ] , expression [ , style ] )





Examples

SELECT CAST('127' AS NUMERIC);
SELECT CAST('127.86' AS NUMERIC(19,3));
SELECT CAST('127.862' AS NUMERIC(19,3));

SELECT CONVERT(NUMERIC, '123');
SELECT CONVERT(NUMERIC, '123.45');
SELECT CONVERT(NUMERIC, '123.75');

SELECT CONVERT(NUMERIC(19,4), '123.45');
SELECT CONVERT(NUMERIC(19,4), '123.4567');