Cast vs. Convert

  • I thought I knew the answer, but BZZZZZZT!

    Nice question.

    Tom Garth
    Vertical Solutions[/url]

    "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
  • 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?

  • 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?

    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. 😀

    --

    Kevin C.

  • KevinC. (3/8/2010)


    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?

    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. 😀

    --

    Kevin C.

    Thanks Kevin, if you are correct than that makes sense now.

  • sknox (3/8/2010)


    Rune Bivrin (3/8/2010)


    Good question, but which alternative is correct depends on how you define platform. If you define "platform" as "versions of SQL Server", then CONVERT works in every version whereas CAST was introduced in 7.0 (IIRC - could've been 2000).

    Well, if you define "black" as "white", you can prove anything. The standard definition of platform is independent of versions of specific platforms. I think it's quite ironic that you're criticizing a question that compares an ANSI standard function to a vendor-specific function by relying on a non-standard definition.

    Who says I'm criticizing the question?

    I'm merely pointing out that since this is SQL Server Central, and not DBMS central, such an interpretation isn't completely out of order. And from that point of view CONVERT is somewhat more universal, even if I sincerely hope noone still wrestles with SQL Server 6.5...


    Just because you're right doesn't mean everybody else is wrong.

  • 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....

  • 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 🙂 )

  • 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"

  • Can anyone else hear that high-pitched whining sound in here? 😛 😉 😀

  • 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.

  • Paul White (3/9/2010)


    Can anyone else hear that high-pitched whining sound in here? 😛 😉 😀

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

    Tom

  • this question is ambiguous, both answers 2 and 4 are almost the same

  • 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[/url]

    "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
  • jmatayoshi (3/11/2010)


    both answers 2 and 4 are almost the same

    That statement makes my head spin.

  • 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[/url]
    Learn Extended Events

Viewing 15 posts - 16 through 30 (of 34 total)

You must be logged in to reply to this topic. Login to reply