Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

Len function doesn't count trailing blanks of words

Jan 25 2013 12:00AM by Alok Chandra Shahi   

It is very small point but developers are unaware of it that's why i am sharing it here.

Len function in sql server returns total no of characters in any string which is passed to it as a parameter,but it excludes trailing blanks

example

 select LEN('abc '),LEN(' abc')

the output of above given query is

(No column name)    (No column name)
3   4

It works same with char and varchar both datatypes.

Read More..   [32134 clicks]

Published under: SQL Server Tips · TSQL Tips ·  ·  · 


Alok Chandra Shahi
70 · 3% · 810
4
 
2
 
 
0
Incorrect
 
0
Interesting
 
0
Forgotten



Submit

7  Comments  

  • Hi Alok Chandra,

    Nice Observation. you can use LTRIM function to work around this.

    SELECT LEN('abc ') as A, LEN(LTRIM(' abc')) as B

    thanks for sharing your thoughts.

    commented on Jan 26 2013 2:30AM
    Bala Krishna
    84 · 2% · 676
  • Hi Bala,

    That depends on what you want. Eg if you want the real length you have to use something like this.

    SELECT LEN(field+'A')-1 as A

    commented on Jan 26 2013 3:22AM
    johan.parlevliet
    733 · 0% · 45
  • If you need trailing spaces, use DATALENGTH() instead of LEN()

    commented on Jan 26 2013 9:27AM
    Marc Jellinek
    96 · 2% · 586
  • Hi Marc Jellinek,

    Yes your correct.Thanks for your comment

    commented on Jan 26 2013 11:07PM
    Bala Krishna
    84 · 2% · 676
  • Hi Johan parieviet,

    Thanks for sharing your thoughts.

    And also you can use DATALENGTH() function [ As for Marc Jellinek comment]

    Thanks again.

    commented on Jan 26 2013 11:15PM
    Bala Krishna
    84 · 2% · 676
  • DATALENGTH() will work for String but not for INT as string datatype occupies 1byte for each character whereas INT occupies 4 bytes for any number...

    commented on Jul 30 2013 5:02AM
    Vipul Patel
    570 · 0% · 66
  • @Vipul, the thread is about strings, not ints. As you note, an int is always going to take up 4 bytes, there is no reason to use LEN() or DATALENGTH() on an int.

    commented on Aug 11 2013 8:43PM
    Marc Jellinek
    96 · 2% · 586

Your Comment


Sign Up or Login to post a comment.

"Len function doesn't count trailing blanks of words" rated 5 out of 5 by 4 readers
Len function doesn't count trailing blanks of words , 5.0 out of 5 based on 4 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]