CONVERT is SQL Server specific, CAST is ANSI.

CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.

EDIT:

As noted by @beruic and @C-F in the comments below, there is possible loss of precision when an implicit conversion is used (that is one where you use neither CAST nor CONVERT). For further information, see CAST and CONVERT and in particular this graphic: SQL Server Data Type Conversion Chart. With this extra information, the original advice still remains the same. Use CAST where possible.

Answer from Matthew Farwell on Stack Overflow
🌐
Reddit
reddit.com › r/sql › cast vs convert?
r/SQL on Reddit: Cast vs convert?
March 29, 2024 -

I am trying to understand the difference between cast and convert.

I have googled it, and looked for explanations online and there are LOTS of them and I think this might just be a me thing, but for me, when I am learning something new I find it helpful when it is explained in a way that is simple and with minimal jargon (which I know is kind of hard because none of you really know where I am at in my SQL learning journey). So I thought I would just post here to ask a noob question lol 😛

🌐
SQL Server Science
sqlserverscience.com › home › performance › performance of cast vs convert
Performance of CAST vs CONVERT - SQL Server Science
August 28, 2019 - (1000000 rows affected) As you can see from the output above, CAST is very slightly quicker. If you re-run this test code many times, you’ll see results that vary slightly. Below, I show the CPU and Elapsed times for 10 runs of the test code above.
🌐
Medium
medium.com › @jagadeshjamjalanarayanan › when-to-use-sql-cast-vs-convert-de044ce3e860
When to use SQL Cast vs Convert. Photo by Campaign Creators on Unsplash | by Jagadesh Jamjala | Medium
January 17, 2024 - The CAST function is used to explicitly convert an expression or value from one data type to another. It follows the syntax: ... This example converts a string representation of a date to the DATE data type.
🌐
AWS
docs.aws.amazon.com › aws database migration service › microsoft sql server 2019 to amazon aurora postgresql migration playbook › migrating t-sql features › sql server cast and convert for t-sql
SQL Server cast and convert for T-SQL - SQL Server to Aurora PostgreSQL Migration Playbook
CREATE A CAST defines a new cast on how to convert between two data types. Cast can be EXPLICITLY or IMPLICIT. The behavior is similar to SQL Server’s casting, but in PostgreSQL, you can also create your own casts to change the default behavior.
🌐
C# Corner
c-sharpcorner.com › UploadFile › rohatash › cast-and-convert-function-in-sql-server
Cast() and Convert() Functions in SQL Server
January 20, 2023 - The example is developed in SQL Server 2012 using the SQL Server Management Studio. The Cast() function is used to convert a data type variable or data from one data type to another data type.
🌐
Quora
quora.com › What-is-the-difference-between-CAST-and-CONVERT-in-SQL-Server-Oracle-MS-Access-or-MySQL
What is the difference between CAST and CONVERT in SQL Server, Oracle, MS Access, or MySQL? - Quora
Answer: CAST ( AS ) is the ANSI standard syntax. It converts the expression from whatever datatype it is in to the data type given as the second parameter. The standards have a table of allowed conversions.
🌐
SQLZealots
sqlzealots.com › tag › difference-between-cast-and-convert-in-sql-server
Difference between CAST and CONVERT in SQL Server – SQLZealots
CAST is an ANSI SQL Standard, however, CONVERT is a SQL Server specific. CAST is single form result function, other hand, CONVERT function results as style format defined. There are NO major notable difference observed in performance.
Find elsewhere
🌐
Essential SQL
essentialsql.com › home › what is the difference between cast versus convert?
What is the Difference between Cast versus Convert? - Essential SQL
July 10, 2022 - ... This is the wordiest article to say “There’s no difference”. ... The difference is you cannot do formatting using the CAST function, whereas, you can perform formatting using the CONVERT function.
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › functions › cast-and-convert-transact-sql
CAST and CONVERT (Transact-SQL) - SQL Server | Microsoft Learn
Reference for the CAST and CONVERT Transact-SQL functions. These functions convert expressions from one data type to another.
🌐
Reintech
reintech.io › blog › understanding-sql-cast-convert-functions
SQL 'CAST' & 'CONVERT' Functions | Reintech media
September 26, 2023 - Both functions are used for data type conversion, with 'CONVERT' providing additional flexibility in output formatting. However, 'CAST' is more universally supported across SQL dialects, making it more portable.
🌐
Explo
explo.co › sql-tutorial › sql-cast-and-convert
Learn SQL CAST and CONVERT
The CAST and CONVERT functions, though similar in their purpose of data type conversion, differ slightly in their syntax and usage. Both functions allow for the conversion of a value from one data type to another, facilitating operations that might otherwise be incompatible due to data type discrepancies. CAST Function: The CAST function is used to convert a value from one data type to another using a straightforward syntax. It follows the standard SQL syntax, making it widely applicable across different SQL databases.
🌐
Richinsql
richinsql.com › 2022 › 04 › whats-the-difference-between-cast-convert
What's the difference between CAST & CONVERT
As you can see, we are able to pass the data type we want to convert, the data itself and also the style we want the data to be returned in. It is also possible to just get the time from a DATETIME column using CONVERT to do that we can specify a varchar length and the style. ... CAST allows you to convert values from one datatype to another but you can’t ask for a specific style to be returned which makes this function less flexibile than CONVERT for example lets take our GETDATE() example again, we want just the date portion of the returned value, to do that we would use this syntax
🌐
Difference Between
differencebetween.net › technology › software-technology › difference-between-cast-and-convert-2
Difference Between CAST and CONVERT | Difference Between | CAST vs CONVERT
August 29, 2017 - In many instances, both CAST and ... implicit conversions occur. The first difference between CAST and CONVERT is CAST is an ANSI standard while CONVERT is a specific function in the SQL server....
🌐
MSSQLTips
mssqltips.com › home › sql convert, cast, try_cast, try_convert and try_parse examples
SQL CONVERT, CAST, TRY_CAST, TRY_CONVERT and TRY_PARSE Examples
August 30, 2022 - You can see that there was not a massive difference between the two. I performed a test not included here on a table with about a million rows of dates and found comparable results between the two functions. In this SQL tutorial, I demonstrated three ways to overcome data type conversion errors with Transact-SQL code for a SQL database. We looked at some examples with TRY_CAST, TRY_CONVERT...
🌐
SQL Shack
sqlshack.com › overview-of-the-sql-cast-and-sql-convert-functions-in-sql-server
SQL CAST and SQL CONVERT function overview
June 25, 2019 - When we deal with two values which are same in nature but different data types, behind the scenes, the database engine convert the lower data type values to higher data type before it could go ahead with the calculation. This type is known as an implicit conversion. On the other hand, we have explicit conversions where you either call a SQL CAST or SQL CONVERT function to change the data type.