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 ««12345»»»

PRINT vagaries Expand / Collapse
Author
Message
Posted Wednesday, June 30, 2010 2:07 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 11:33 PM
Points: 361, Visits: 510
Good tricky one...thank you
It would be even trickier if the first answer was 5.

Hrvoje


Hrvoje Piasevoli
Post #945280
Posted Wednesday, June 30, 2010 2:22 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354, Visits: 1,299
info 25880 (6/30/2010)
Yes, that's reason, because the result of an implicit casting of '-' is zero
SELECT 6 + 1 + '-'



So if you substitute the '-' with something clearly a string like 'a', you get a conversion failed message.
Post #945291
Posted Wednesday, June 30, 2010 3:05 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:21 PM
Points: 6,156, Visits: 8,416
Good question. The only thing I dislike about it is the description "PRINT vagaries" because, as others have noted, the PRINT statement is completely innocent.

A better name would have been "Implicit type casting vagaries".



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #945313
Posted Wednesday, June 30, 2010 4:38 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, December 5, 2013 8:42 AM
Points: 455, Visits: 24
Nice question. At first glance my answer would have been 5, but as this was not an option, I had to review the question.

I think more people would have been caught out if 5 had been an answer.
Post #945347
Posted Wednesday, June 30, 2010 5:36 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 7:16 AM
Points: 118, Visits: 174
Excellent question and great to know the deal

Prashant Bhatt
Sr Engineer - Application Programming
Post #945373
Posted Wednesday, June 30, 2010 5:57 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, December 19, 2014 7:51 AM
Points: 42, Visits: 85
I was surprised to find that '-' converts to 0. I expected the print statement would have producted "Conversion failed when converting the varchar value '-' to data type int." You could've tricked us by putting that as one of the choices.
Post #945383
Posted Wednesday, June 30, 2010 5:59 AM


SSC-Insane

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

Group: General Forum Members
Last Login: Yesterday @ 1:00 PM
Points: 20,594, Visits: 9,626
Hehe, got me too. Never dreamed that '-' and '+' converts to 0. Tho it makes perfect sens when you think about it!
Post #945386
Posted Wednesday, June 30, 2010 6:01 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 2:56 AM
Points: 2,842, Visits: 3,876
kimetch (6/30/2010)
I was surprised to find that '-' converts to 0. I expected the print statement would have producted "Conversion failed when converting the varchar value '-' to data type int." You could've tricked us by putting that as one of the choices.

Interestingly, you get an overflow when working with decimal instead:
SELECT CAST('-' AS decimal(38,19))



Best Regards,
Chris Büttner
Post #945387
Posted Wednesday, June 30, 2010 6:23 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, December 19, 2014 5:47 AM
Points: 430, Visits: 996
cengland0 (6/30/2010)
info 25880 (6/30/2010)
Yes, that's reason, because the result of an implicit casting of '-' is zero
SELECT 6 + 1 + '-'



So if you substitute the '-' with something clearly a string like 'a', you get a conversion failed message.


My first thought was that the correct answer would have been the conversion failed because of the dash. When it was not in the options of possible answers, I guessed incorrectly with the 6-1. Always nice to learn something new.
Post #945404
Posted Wednesday, June 30, 2010 7:00 AM
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: Wednesday, December 10, 2014 10:00 AM
Points: 585, Visits: 611
I agree with the posts saying that '5' should've been an option as I would've definitely chose that. When I first read through the answer list, and saw that 5 wasn't an option, I thought maybe it was printing the values as strings so chose 6-1, but understand now after reading the description that the math ends up being 6+0+1.

Great question - learned something.
Post #945436
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse