Possible Duplicate:
T-SQL Cast versus Convert
What is the major difference between CAST
and CONVERT
in SQL cause both performs data type conversion?
CAST and CONVERT are two SQL functions used by programmers to convert one data type to another. 2. The CAST function is ANSI standard and is compatible to use in other databases while the CONVERT function is a specific function of the SQL server.
The cast and convert functions provide similar functionality. They are used to convert a value from one data type to another. So let's take a look at a practical example. The example is developed in SQL Server 2012 using the SQL Server Management Studio.
Summary. Casting and converting are ways in which we can change a value from one type to another; casting is faster but more prone to errors, while conversion is more computationally expensive but also more forgiving.
The SQL CAST function converts the data type of an expression to the specified data type. For a list of the data types supported by InterSystems SQL, see Data Types. CAST is similar to CONVERT, with these differences: CONVERT is more flexible than CAST.
CAST and CONVERT have similar functionality. CONVERT is specific to SQL Server, and allows for a greater breadth of flexibility when converting between date and time values, fractional numbers, and monetary signifiers. CAST is the more ANSI-standard of the two functions. Check this blog for examples of using both of those: http://sqltutorials.blogspot.com/2007/06/sql-cast-and-convert.html
The convert
function can do more complex conversions, for example converting a datetime
value into varchar
using a specific format:
convert(varchar(16), dateTimeValue, 120)
Assuming you're talking about SQL Server.
From http://msdn.microsoft.com/en-us/library/ms187928.aspx and http://msdn.microsoft.com/en-us/library/aa226054(v=sql.80).aspx
Explicitly converts an expression of one data type to another. CAST and CONVERT provide similar functionality.
So yes, they are functionally the same. They just have different syntax that allows for more complex conversions or (subjectively) improved readability.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With