PRINT vagaries

  • Ol'SureHand


    Points: 2744

    Comments posted to this topic are about the item PRINT vagaries

  • UMG Developer


    Points: 13482

    Nice question thanks!

  • Henrico Bekker

    One Orange Chip

    Points: 27652

    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

  • udayroy15

    Ten Centuries

    Points: 1076

    Interesting & tricky!!

  • Kari Suresh

    Hall of Fame

    Points: 3712

    [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

  • Atif-ullah Sheikh


    Points: 12495

    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]

  • dgvozdetsky


    Points: 2464

    Good question!!! Thanks!:-)

  • Christian Buettner-167247


    Points: 13729

    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

  • dbuendiab

    SSC Eights!

    Points: 993

    I'm surprised but is true:

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

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

  • info 25880

    SSC Enthusiast

    Points: 177

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

    SELECT 6 + 1 + '-'

  • hrvoje.piasevoli

    Ten Centuries

    Points: 1377

    Good tricky one...thank you

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


    Hrvoje Piasevoli

  • cengland0


    Points: 6102

    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.

  • Hugo Kornelis

    SSC Guru

    Points: 64675

    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:

  • TonyThorne

    Right there with Babe

    Points: 749

    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.

  • prashant.bhatt


    Points: 476

    Excellent question and great to know the deal

    Prashant Bhatt
    Sr Engineer - Application Programming

Viewing 15 posts - 1 through 15 (of 50 total)

You must be logged in to reply to this topic. Login to reply