LEN()

  • Comments posted to this topic are about the item LEN()

  • Good question, thanks!

    Though I probably would have had the second option be 5, 2, 3...

  • what's new in this question ?????

  • One easy point for me!

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • This one got me. I selected 5,5,5 because I'm used to having padding spaces with the CHAR datatype. That's why I use Varchar instead when the contents of the column doesn't contain a consistent number of characters.

    if you were to select them without the LEN function, you would get

    abcde ab... ab...

    (the period was used to make spaces visible).

  • It's probably also worth pointing out that if you actually did want the physical length of the variables, you would use DATALENGTH() instead of LEN().

  • Aargh!! Again my initial reaction was "that's easy it's 5,2,2 as LEN ignores spaces"... and then "hmmm, but that's too easy, there must be a trick in there"... and after a bit of reading went against my initial conclusion...

    Doh!! 🙁

    Good lesson though... trust yourself!

    _____________________________________________________________________
    [font="Comic Sans MS"]"The difficult tasks we do immediately, the impossible takes a little longer"[/font]

  • Thanx a lot

    everyday I learn from you new things...

  • crussell-931424 (6/15/2010)


    Yep, it only does an RTRIM, not an LTRIM.

    This variation to the question may have been a better teaser 🙂

  • rjv_rnjn (6/15/2010)


    crussell-931424 (6/15/2010)


    Yep, it only does an RTRIM, not an LTRIM.

    This variation to the question may have been a better teaser 🙂

    Good point. In a month or so, this RTRIM/LTRIM variation would be a good question, after everyone has forgotten this question, and its discussion.

  • F1Droid (6/15/2010)


    Aargh!! Again my initial reaction was "that's easy it's 5,2,2 as LEN ignores spaces"... and then "hmmm, but that's too easy, there must be a trick in there"... and after a bit of reading went against my initial conclusion...

    Doh!! 🙁

    Good lesson though... trust yourself!

    Yes, the same thing happened to me.

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • Easy basic programming RTRIM question.

    SQL DBA.

  • UMG Developer (6/14/2010)


    ...I probably would have had the second option be 5, 2, 3...

    Agreed. I think 5,2,5 makes no sense and should influence a decision in favor of 5,2,2.

  • As usual, I learn more from the discussion than the original question.

    If this had been the question:

    SET @aa = 'abcde';SET @bb = ' ab';SET @cc = 'ab '

    I would have gotten it wrong.

    (I meant no disrespect to the author of the question. My point was that a thread of "what if this" and "what if that" is always educational.)

  • wware (6/15/2010)


    As usual, I learn more from the discussion than the original question.

    If this had been the question:

    SET @aa = 'abcde';SET @bb = ' ab';SET @cc = 'ab '

    I would have gotten it wrong.

    I was a bit nervous before I answered the question that there was more to the question like what your example was.

    ---------------------------------------------------------------------
    Use Full Links:
    KB Article from Microsoft on how to ask a question on a Forum

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

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