Showing posts with label cast. Show all posts
Showing posts with label cast. Show all posts

Wednesday, 1 December 2010

SQL Server: basic functions (part 3) - Cast and Convert

   


Following the other 2 parts of the series, in this short article we are going to see how to convert data in a query.

Cast and Convert: why 2 functions?
Cast and Convert are two functions used to convert data. I've always been confused by the fact that there are actually 2 functions to - apparently - perform the same operation. First of all, I must say that CONVERT can be used only in Sql Server while CAST derives from the ANSI standard. Wow! And so? CONVERT is undoubtedly more flexible while CAST is in a way a standard, it is more portable (it works in almost in any db environment), but it is less powerful. On top of that, CAST is preferably used when converting between decimal and numeric values to preserve the number of decimal places.