|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 5:22 AM
Points: 1,037,
Visits: 1,354
|
|
I've done a lot of SQLXML programming with simple queries in XML files and XSLT files to transform those query results to HTML pages. I used CONVERT a lot to convert money and datetime values to varchar in the format I needed before it even gets to the XSLT, saving a lot of messy XSL formatting on the front end.
I'm quite surprised that, at the time I answered the question, approximately 3/4 of people got this question wrong. Just under 1/3 of respondents thought there was no real difference! This question, to me, is T-SQL 101. Even if you don't know that CONVERT() is T-SQL-specific, you should know the differences in inputs and potential outputs.
This is not criticism of those who got the question wrong: we all have holes in our knowledge. But it does highlight the value of this QoTD. Before this question, I would have assumed this to be a universally-known topic in MSSQL circles. Now I know I can't make that assumption. And now those who didn't know of the difference have learned something.
Great question!
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 5:22 AM
Points: 1,037,
Visits: 1,354
|
|
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.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Thursday, May 16, 2013 1:46 PM
Points: 18,732,
Visits: 12,329
|
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Thursday, May 16, 2013 1:46 PM
Points: 18,732,
Visits: 12,329
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 6:38 PM
Points: 7,077,
Visits: 7,116
|
|
Paul White (3/8/2010)
I am shocked and appalled that Jeff hasn't posted anything about code portability being a myth yet. Very disappointing  I love CONVERT. I'm sure he will soon. Worrying about portability is crazy until we get a relational dbms with a relational language - then we can just worry about porting to that.
Tom Que conclure à la fin de tous mes longs propos? C'est que les préjugés sont la raison des sots. (Voltaire, 1756)
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Friday, February 04, 2011 7:20 AM
Points: 977,
Visits: 1,499
|
|
I thought I knew the answer, but BZZZZZZT!
Nice question.
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
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 8:33 AM
Points: 522,
Visits: 191
|
|
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?
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Tuesday, December 07, 2010 12:55 AM
Points: 771,
Visits: 504
|
|
erwin.oosterhoorn (3/8/2010)
bouarroudj Mohamed (3/8/2010) CONVERT works across all platforms & has more capabilities in SQL Server is also trueThat 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.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 8:33 AM
Points: 522,
Visits: 191
|
|
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 trueThat 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.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 12:46 AM
Points: 2,655,
Visits: 717
|
|
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.
|
|
|
|