Differences between CAST() and CONVERT() Functions

 

# CAST() and CONVERT() Functions

The CAST and CONVERT functions are both used to convert data from one data type to another.

SELECT CAST ('10' as int) * 20;        --outpout=200

SELECT CONVERT (int, '10') * 20;       --outpout=200 

In both cases, we’re converting from the text value ’10’ to its integer representation. 


  • In many ways CAST and CONVERT are similar. Both are used to convert data from one type to another.  Thought their syntax is different, both functions are able to convert values from one formation to another.
  • CAST is part of the ANSI-SQL specification; whereas, CONVERT is not.  In fact, CONVERT is SQL implementation-specific.

No comments:

Post a Comment