June 29, 2010 at 9:45 pm
Comments posted to this topic are about the item PRINT vagaries
June 29, 2010 at 9:53 pm
Nice question thanks!
June 29, 2010 at 11:14 pm
Good tricky one...thank you
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle
June 30, 2010 at 12:06 am
Interesting & tricky!!
June 30, 2010 at 12:13 am
[p]Yes.. it is tricky, this query also results the same..[/p]PRINT LEN(@StringArray) + '-' + LEN(@Delimiter)
KSB
-----------------------------
Thousands of candles can be lit from a single candle, and the life of the candle will not be shortened. Knowledge and happiness never decreases by being shared.” - Buddha
June 30, 2010 at 12:33 am
Good question..
And its because the datatype of the variables ( @lenStringArray and @lenDelimiter) is INT.
June 30, 2010 at 12:35 am
Good question!!! Thanks!:-)
June 30, 2010 at 12:57 am
Nice question, but this is not a "PRINT vagary". Instead this is just how type conversion works (http://msdn.microsoft.com/en-us/library/ms190309.aspx).
SELECT @lenStringArray + '-' + @lenDelimiter
behaves the same way, because int (@lenStringArray & @lenDelimiter) has a higher precedence than varchar(1) ('_').
Best Regards,
Chris Büttner
June 30, 2010 at 1:29 am
I'm surprised but is true:
Select Cast( '+' as int ) --> 0
Select Cast( '-' as int ) --> 0
June 30, 2010 at 2:04 am
Yes, that's reason, because the result of an implicit casting of '-' is zero
SELECT 6 + 1 + '-'
June 30, 2010 at 2:07 am
Good tricky one...thank you
It would be even trickier if the first answer was 5.
Hrvoje
Hrvoje Piasevoli
June 30, 2010 at 2:22 am
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.
June 30, 2010 at 3:05 am
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".
June 30, 2010 at 4:38 am
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.
June 30, 2010 at 5:36 am
Excellent question and great to know the deal
Prashant Bhatt
Sr Engineer - Application Programming
Viewing 15 posts - 1 through 15 (of 49 total)
You must be logged in to reply to this topic. Login to reply