Friday, December 17, 2010
How to find the length of a string in SQL Server
Determining a string's length is extremely useful in SQL Server! The best way to determine a length of a string in SQL Server's transact SQL is to use the built in LEN function. This function returns a string's length. The LEN function may be used in SELECT queries, for example to find rows where colums are a particular length: SELECT * FROM t_Books WHERE LEN(t_Books.BookTitle) BETWEEN 10 AND 50 Note that LEN only works with string datatypes, and it exludes any trailing blank spaces that may be present in a field. For columns containing byte data, consider using the DATALENGTH function.