Monday, February 13, 2012

What is The Differences between CAST and CONVERT IN SQL SERVER

You can use either CAST or CONVERT. Because CAST and CONVERT provide similar functionality.
Because SQL Server provides both functions, there may be some confusion about which is best to use and under what circumstances. 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, 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 andnumeric 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 onlyCONVERT can provide in the work you're doing.

CAST and CONVERT can also be used in conjunction with each other to achieve certain effects. For instance, a typical way to produce a char variable with the current date would be to use:


Twitter Delicious Facebook Digg Stumbleupon Favorites More

Powered by Code Imagine