PRINT vagaries

  • Comments posted to this topic are about the item PRINT vagaries

  • Nice question thanks!

  • 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

  • Interesting & tricky!!

  • [p]Yes.. it is tricky, this query also results the same..[/p]PRINT LEN(@StringArray) + '-' + LEN(@Delimiter)

    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

  • Good question..

    And its because the datatype of the variables ( @lenStringArray and @lenDelimiter) is INT.

    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • Good question!!! Thanks!:-)

  • Nice question, but this is not a "PRINT vagary". Instead this is just how type conversion works (

    SELECT @lenStringArray + '-' + @lenDelimiter

    behaves the same way, because int (@lenStringArray & @lenDelimiter) has a higher precedence than varchar(1) ('_').

    Best Regards,

    Chris Büttner

  • I'm surprised but is true:

    Select Cast( '+' as int ) --> 0

    Select Cast( '-' as int ) --> 0

  • Yes, that's reason, because the result of an implicit casting of '-' is zero

    SELECT 6 + 1 + '-'

  • Good tricky one...thank you

    It would be even trickier if the first answer was 5.


    Hrvoje Piasevoli

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

  • 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/Data Platform MVP (2006-2016)
    Visit my SQL Server blog:
    SQL Server Execution Plan Reference:

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

  • 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