Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

SQL Server - Difference between TSQL Functions CAST() and CONVERT()

Jul 22 2010 8:19AM by Madhivanan   

Both these functions are used to convert values from one datatype to another
But there are some differences between them

1 CAST is ANSI standard and CONVERT is specific to SQL Server
2 CAST can't be used for formating purposes.
But CONVERT can be used for formating purposes particularly on datetime and money datatype 

declare @d datetime
set @d='20001210 12:34:22'
select convert(varchar(10),@d,108)
declare @m money
set @m=23498
select convert(varchar(10),@m,1)

Results are

----------
12:34:22

----------
23,498.00

3 CAST can't simulate set dateformat option. But CONVERT can simulate it
The following example specifies that date value is in the format of dmy (style 103 is for dmy)

select convert(datetime,'19/12/2008 12:34:22',103)

Result is

-----------------------
2008-12-19 12:34:22.000

Also you should be very careful in using the both when you convert integer values to character datatype
Consider the following example

declare @i int
set @i=123456
select convert(char(5),@i),cast(@i as char(5))

The result is

----- -----
*     *    

It is becuase the size of the variable is not enough to hold the number In this case you wont get any error.
You should in advance specify the enough length

Tags: t-sql, sql_server, tsql, BRH, #TSQL, cast, convert, #SQLServer,


Madhivanan
3 · 39% · 12430
8
 
0
Lifesaver
 
 
0
Learned
 
0
Incorrect



Submit

3  Comments  

  • Good Explain..

    commented on Jul 26 2010 2:06AM
    Manigandan
    791 · 0% · 36
  • For data extraction purpose, with 1M+ records, which method is faster/recommended ? CAST or CONVERT from: (i) Date to varchar (ii) Int to varchar

    commented on Jul 27 2010 7:38AM
    cute_boboi
    2893 · 0% · 2
  • Hello, Madhivanan!

    Great post!

    I have attempted to answer the question put forward by "cuteboboi" in my post here - http://beyondrelational.com/blogs/nakul/archive/2011/01/03/CAST-v-s-CONVERT.aspx

    Do let me know your feedback on the same.

    commented on Dec 31 2010 10:10AM
    Nakul Vachhrajani
    4 · 33% · 10575

Your Comment


Sign Up or Login to post a comment.

"SQL Server - Difference between TSQL Functions CAST() and CONVERT()" rated 5 out of 5 by 8 readers
SQL Server - Difference between TSQL Functions CAST() and CONVERT() , 5.0 out of 5 based on 8 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]