Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234»»

Cast vs. Convert Expand / Collapse
Author
Message
Posted Monday, March 8, 2010 11:22 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Saturday, April 16, 2011 10:29 AM
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....
Post #879132
Posted Tuesday, March 9, 2010 3:26 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, May 9, 2014 12:47 AM
Points: 3,448, Visits: 4,407
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.

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 )
Post #879213
Posted Tuesday, March 9, 2010 3:28 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, March 6, 2014 1:05 PM
Points: 1,334, Visits: 3,068
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. ..."
Post #879215
Posted Tuesday, March 9, 2010 3:34 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 8:01 AM
Points: 11,194, Visits: 11,165
Can anyone else hear that high-pitched whining sound in here?



Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #879219
Posted Tuesday, March 9, 2010 3:34 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, May 9, 2014 12:47 AM
Points: 3,448, Visits: 4,407
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.
Post #879220
Posted Tuesday, March 9, 2010 8:52 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 8:01 PM
Points: 8,823, Visits: 9,381
Paul White (3/9/2010)
Can anyone else hear that high-pitched whining sound in here?

Yes, I hear it loud and clear. Pitiful , ain't it? . And just a little nauseating .


Tom
Post #879450
Posted Thursday, March 11, 2010 12:01 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, February 19, 2013 9:08 AM
Points: 1,511, Visits: 81
this question is ambiguous, both answers 2 and 4 are almost the same

Post #881242
Posted Thursday, March 11, 2010 4:00 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, February 4, 2011 7:20 AM
Points: 977, Visits: 1,499
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
Post #881408
Posted Friday, March 12, 2010 12:22 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 8:01 AM
Points: 11,194, Visits: 11,165
jmatayoshi (3/11/2010)
both answers 2 and 4 are almost the same

That statement makes my head spin.




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #881522
Posted Friday, March 12, 2010 12:31 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 4:51 PM
Points: 21,733, Visits: 15,424
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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #881528
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse