Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Cast vs. Convert


Cast vs. Convert

Author
Message
Joe SQL
Joe SQL
Mr or Mrs. 500
Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)

Group: General Forum Members
Points: 502 Visits: 399
I figured the answer was going to be something related to CONVERT having the style parameter (and hence more capabilities), but then saw in BOL (2005) that "CAST and CONVERT provide similar functionality" so chose the last answer.. doh! Should have gone with gut feeling but have been tricked too many times from previous questions which always give the BOL answer as the correct one (even if it isn't). Although I see now that BOL for 2008 does not have that statement in it.

Just can't win....
vk-kirov
vk-kirov
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3494 Visits: 4408
erwin.oosterhoorn (3/8/2010)
bouarroudj Mohamed (3/8/2010)
CONVERT works across all platforms & has more capabilities in SQL Server is also true


That is what I am looking at as well, does this not mean the same as the given right answer?
If one has less the other must have more?

I agree with this. The phrasing of the answers seems quite ambiguous to me.

"CAST ... has less capabilities in SQL Server" – according to what? According to "CAST in another RDBMS", according to "CAST in SQL-92", or according to "CONVERT in MSSQL/another RDBMS"?

KevinC. (3/8/2010)
If I understand correctly, CONVERT is MS SQL specific whereas CAST is ANSI-SQL and will work on multiple platforms (i.e. Oracle, DB2, etc.).

Therefore, the above statement is incorrect because CONVERT does NOT work across all platforms (though it does have more capabilities in SQL Server).

Please correct me if I'm wrong. :-D

CONVERT is not MSSQL specific, it also works on Sybase ASA/ASE.
Also CONVERT exists in SQL-92, but has different meaning (see below).

I had checked documentation on several RDBMS platforms (MSSQL, Sybase, Oracle, DB2, PostgreSQL, MySQL) before I answered the question, here is the result:
– CAST works across all these platforms, and may have additional MULTISET parameter in Oracle;
– CONVERT works across all platforms, but has two different meanings. In MSSQL/Sybase it converts data from one type to another, in other databases it converts text data from one encoding to another (therefore working like COLLATE clause in MSSQL), as described in SQL-92.

Also I found an issue in the QOD explanation:
agrawal.prakriti
CAST is the more ANSI-standard of the two functions, meaning that while it's more portable

This sentence is somewhat incomplete, isn't it? (although I'm a total noob at English language :-) )
TravisDBA
TravisDBA
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1462 Visits: 3069
bouarroudj Mohamed (3/8/2010)
CONVERT works across all platforms & has more capabilities in SQL Server is also true


My thinking exactly and that was my answer too, which I got wrong. Question was a little confusing and nebulous..

"Technology is a weird thing. It brings you great gifts with one hand, and it stabs you in the back with the other. ...:-D"
Paul White
Paul White
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10338 Visits: 11350
Can anyone else hear that high-pitched whining sound in here? :-P ;-) :-D



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
vk-kirov
vk-kirov
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3494 Visits: 4408
sknox (3/8/2010)
I'm quite surprised that, at the time I answered the question, approximately 3/4 of people got this question wrong.

Do you think this is because lack of knowledge? I think many people answered "incorrect" because of the phrasing.
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10704 Visits: 12001
Paul White (3/9/2010)
Can anyone else hear that high-pitched whining sound in here? :-P ;-) :-D

Yes, I hear it loud and clear. Pitiful Crying, ain't it?:-D ;-). And just a little nauseating Sick Laugh.

Tom

jmatayoshi
jmatayoshi
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1511 Visits: 81
this question is ambiguous, both answers 2 and 4 are almost the same
Tom Garth
Tom Garth
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1013 Visits: 1499
jmatayoshi (3/11/2010)
this question is ambiguous, both answers 2 and 4 are almost the same



So Almost the Same = Ambiguous?

What if they were Somewhat Different? Would that be better?

Tom Garth
Vertical Solutions

"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers

Paul White
Paul White
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10338 Visits: 11350
jmatayoshi (3/11/2010)
both answers 2 and 4 are almost the same

That statement makes my head spin.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21075 Visits: 18259
Paul White (3/12/2010)
jmatayoshi (3/11/2010)
both answers 2 and 4 are almost the same

That statement makes my head spin.



Hah - Paulpatine spinning like the MCP before Tron obliterates it with the disk - oh yeah.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search