Submit Post - Article - Ask a Question - Ask an Interview Question - Submit Useful Links

What is a convert function in database?

By Arsal Ahmed   Posted on March-20-2018   393

In SQL Server, the Convert function converts an expression from one datatype to another datatype.


  • The syntax for the CONVERT function in SQL Server (Transact-SQL) is:
  • CONVERT (type [ (length) ], expression [ , style ]  )


  • The datatype that you wish to convert expression to and it can be one of the following are:

bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, text, nchar, nvarchar, ntext, binary, varbinary, or image.


  • Optional. The length of the resulting data type for char, varchar, nchar, nvarchar, binary and varbinary.


  • The value to convert to another datatype.


  • Optional. The format used to convert between datatypes, such as a date format or string format. It can be one of the following values:


Let's look at some SQL Server CONVERT function examples and explore how to use the CONVERT function in SQL Server (Transact-SQL).

For example:

SELECT CONVERT(int, 14.85);

Result: 14 (result is truncated)

By Arsal Ahmed    20-Mar-2018 Views  393

You may also read following recent articles