T-SQL Tutorial

T-SQL Convert


The Convert function convert an value of one data type to another.

Convert Syntax


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



Convert Example


SELECT CONVERT(INT, '444');

SELECT CONVERT(INT, CONVERT(NUMERIC, '444.75'));
SELECT CONVERT(INT, CONVERT(NUMERIC, '444.35'));
SELECT CONVERT(INT, CONVERT(NUMERIC(19,4), '444.35'));

DECLARE @var NUMERIC;
SET @var = 1278.69;
SELECT CONVERT(INT, @var);
SELECT CONVERT(decimal(10,5), CONVERT(varbinary(20), @var));
SELECT CONVERT(VARCHAR, @var);

DECLARE @varchar_date varchar(50);
SET @varchar_date = '2019-08-17 08:03:10'
SELECT CONVERT(datetime, @varchar_date)

See also:
T-SQL Functions
Cast -> Parse -> Try_Cast -> Try_Convert -> Try_Parse