Thursday, 25 October 2012

Difference between cast and convert in sql server?


Both cast and covert serves the same purpose i.e. convert a data type to another.
  • Cast
  1. Cast is  ANSII Standard
  2. Cast cannot be used for Formatting Purposes.
  3. Cast cannot convert a datetime to specific format
  • Convert
  1. Convert is Specific to SQL SERVER
  2. Convert can be used for Formatting Purposes.For example Select convert (varchar, datetime, 101)
  3. Convert can be used to convert a datetime to specific format
examples:
select convert(varchar(20),getdate(),101)
o/p:10/25/2012
select cast('100abcd' as varchar(20))
o/p:101abcd

No comments:

Post a Comment