Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

    Unanswered: Function like Len() that counts white space

    Good day to you, community friend!

    Just a quick one - I swear I've seen a function before that was like Len() but it counted the white spaces too. I have a feeling it was something along the lines of "data_length" but I can't for the life of me find it!

    Many thanks,
    George
    George
    Home | Blog

  2. #2
    Join Date
    Nov 2005
    Posts
    122
    Skip the underscore.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I knew it was something that simple!!
    Cheers keffenils
    George
    Home | Blog

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I appear to have slipped a cog or two here. Can someone explain what georgev meant based on:
    Code:
    DECLARE @c		VARCHAR(50)
    
    SELECT @c = 'This is a test'
    
    SELECT Len(@c), DataLength(@c), @c AS '12345678901234567890'
    -PatP

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Code:
    DECLARE @c VARCHAR(50)
     
    SELECT @c ='This is a test                             '
     
    SELECTLen(@c),DataLength(@c), @c AS'12345678901234567890'
    
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Ah ha! I keep thinking like SQL Server, so trailing whitespace isn't really there in my mind... This was actually a user-required concession to make CHAR() columns function the way that microcomputer programmers expected them to, long before Microsoft inherited the product.

    -PatP

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The trailing spaces are maintained in SQL Server CHAR columns. It is the LEN function that ignores them when returning a value.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by blindman
    The trailing spaces are maintained in SQL Server CHAR columns. It is the LEN function that ignores them when returning a value.
    That's what I thought I said.

    Somewhere prior to 4.0, spaces were left "as is" by functions, including trailing spaces. By the time that 4.21 was released, all of the string functions were supposed to trim trailing spaces before processing, and convert any string results back into the CHAR() type if that is what the function had originally been passed.

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •