Tuesday, 20 January 2009

SQL Server Conversion - Cast or Convert

I've always wondered which to use - Cast or Convert when converting data, well this is what Google suggests. Basically use CAST unless there's a good reason not to.

CAST is the more ANSI-standard of the two functions, meaning that while it's more portable (i.e., a function that uses CAST can be used in other database applications more or less as-is), it's also less powerful. CAST is also required when converting between decimal and numeric values to preserve the number of decimal places in the original expression. For those reasons, it's best to use CAST first, unless there is some specific thing that only CONVERT can provide in the work you're doing


http://searchwinit.techtarget.com/tip/0,289483,sid1_gci1014050,00.html

No comments:

Post a Comment