|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, December 07, 2012 9:27 AM
Points: 361,
Visits: 507
|
|
Good tricky one...thank you It would be even trickier if the first answer was 5.
Hrvoje
Hrvoje Piasevoli
|
|
|
|
|
Ten 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.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 3:49 PM
Points: 5,244,
Visits: 7,063
|
|
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
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Thursday, November 10, 2011 7:03 AM
Points: 446,
Visits: 22
|
|
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.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, March 29, 2013 1:52 AM
Points: 118,
Visits: 166
|
|
Excellent question and great to know the deal
Prashant Bhatt Sr Engineer - Application Programming
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 8:17 AM
Points: 42,
Visits: 65
|
|
| 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.
|
|
|
|
|
SSC-Insane
         
Group: General Forum Members
Last Login: Today @ 3:18 AM
Points: 21,359,
Visits: 9,541
|
|
| Hehe, got me too. Never dreamed that '-' and '+' converts to 0. Tho it makes perfect sens when you think about it!
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 6:12 AM
Points: 2,526,
Visits: 3,620
|
|
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
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 6:20 AM
Points: 376,
Visits: 885
|
|
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.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 11:24 AM
Points: 576,
Visits: 566
|
|
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.
|
|
|
|