What is the CONVERT function in SQL?

CONVERT is one of the most commonly used functions in SQL. The CONVERT() function converts a value (of any type) into a specified datatype.

Syntax

CONVERT(data_type(length), expression, style)

data_type: This is a required parameter. The datatype to convert an expression can be one of the following, bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, text, nchar, nvarchar, ntext, binary, varbinary, or image.

length: This is an optional parameter. It refers to the length of the resulting data type.

expression: This is the required parameter. The value used to convert to another data type.

style: This is an optional parameter. It refers to the format used to convert within data types, such as a date or string format.

Example

  1. The data is converted to a varchar format:
SELECT CONVERT(varchar, '2021-01-25', 101);
// Run SQL
2021-01-25
  1. The decimal value of 33.44 is converted to an int:
SELECT CONVERT(int, 33.44);
// Run SQL
33
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved