How to convert String to INT

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

Syntax

CAST ( expression AS datatype [ ( length ) ] )

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


Examples

SELECT CAST('' AS INT);
SELECT CAST('789' AS INT);

SELECT CAST(CAST ('12345.67' AS NUMERIC) AS INT);
SELECT CAST(CAST ('12345.6789' AS NUMERIC(19,4)) AS INT);

SELECT CONVERT(INT, '123');
SELECT CONVERT(INT, CONVERT(NUMERIC, '123.45'));
SELECT CONVERT(INT, CONVERT(NUMERIC(19,4), '123.45'));