CAST and CONVERT()
Reference for the CAST and CONVERT Transact-SQL functions. These functions convert expressions from one data type to another.
Signature
CAST ( expression AS data_type [ ( length ) ] )Parameters
- expression — Any valid expression.
- data_type — The target data type. This includes xml, bigint, and sql_variant. Alias data types can't be used.
- length — An optional integer that specifies the length of the target data type, for data types that allow a user specified length. The default value is 30.
- style — An integer expression that specifies how the `CONVERT` function will translate *expression*. For a style value of NULL, NULL is returned. *data_type* determines the range.
Examples
SELECT CAST(CAST(0x41 AS nvarchar) AS varbinary);0x4100SELECT CAST('abc' AS varchar(5)) COLLATE French_CS_AS;abcSELECT CAST(10.6496 AS INT) AS trunc1,
CAST(-10.6496 AS INT) AS trunc2,
CAST(10.6496 AS NUMERIC) AS round1,
CAST(-10.6496 AS NUMERIC) AS round2;10|-10|11|-11Run against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.
Available on
- SQL Server 2017 and later
- Azure SQL Database
- Azure SQL Managed Instance
- Azure Synapse Analytics
- Analytics Platform System (PDW)
- Microsoft Fabric warehouse
- Fabric SQL database
Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.