I am very confused about the exact difference between the cast()
function and the convert()
function other than the syntax of course so that I can efficiently decide when to use which.
-
just see https://stackoverflow.com/questions/707335/t-sql-cast-versus-convert. For performance or what you say when to use : https://www.mssqltips.com/sqlservertip/3018/performance-comparison-of-the-sql-server-parse-cast-convert-and-tryparse-trycast-tryconvert-functions/ – Ajay2707 Jan 26 '20 at 08:05
1 Answers
From this link :
CAST is an ANSI standard while CONVERT is a specific function in the SQL server. There are also differences when it comes to what a particular function can and cannot do. For example, a CONVERT function can be used for formatting purposes especially for date/time, data type, and money/data type. Meanwhile, CAST is used to remove or reduce format while still converting. Also, CONVERT can stimulate set date format options while CAST cannot do this function.
CAST is also the more portable function of the two. It means that the CAST function can be used by many databases. CAST is also less powerful and less flexible than CONVERT. On the other hand, CONVERT allows more flexibility and is the preferred function to use for data, time values, traditional numbers, and money signifiers. CONVERT is also useful in formatting the data’s format.
CAST functions also restore the decimals and numerical values to integers while converting. It also can be used to truncate the decimal portion or value of an integer.

- 312
- 3
- 16