Friday, February 15, 2013

SQL SERVER LEN STRING FUNCTION

SQL SERVER LEN STRING FUNCTION

SQL Server Len function-> Len function gets number of characters in the expression(includes leading spaces,excludes trailing spaces), column.
Same rule applies to char,int,date etc.,.
for var... types,  length will be long value.

select len('Hello World!')   -> 12  
select len(N'हिन्दी')   ->  6 
select len('hello')  -> 5
select len(' hello') -> 6  because it has leading space
select len(' hello ')-> 6  it counts leading space ignores trailing space.
select len(ltrim(rtrim(' hello '))-> 5 it removes leading and trailing spaces then counts characters.
select  column length from emp table

ex:
select ename,len(ename),hiredate,len(hiredate),sal,len(sal),empno,len(empno),deptno,len(deptno) from emp

O/P:
ename    (No column name)    hiredate    (No column name)    sal    (No column name)    empno    (No column name)    deptno    (No column name)
SMITH    5    1980-12-17    10    800.00    6    7369    4    20    2
ALLEN    5    1981-02-20    10    1600.00    7    7499    4    30    2
WARD    4    1981-02-22    10    1250.00    7    7521    4    30    2
JONES    5    1981-04-02    10    2975.00    7    7566    4    20    2
MARTIN    6    1981-09-28    10    1250.00    7    7654    4    30    2
BLAKE    5    1981-05-01    10    2850.00    7    7698    4    30    2
CLARK    5    1981-06-09    10    2450.00    7    7782    4    10    2
KING    4    1981-11-17    10    5000.00    7    7839    4    10    2
TURNER    6    1981-09-08    10    1500.00    7    7844    4    30    2
JAMES    5    1981-12-03    10    950.00    6    7900    4    30    2
FORD    4    1981-12-03    10    3000.00    7    7902    4    20    2
MILLER    6    1982-01-23    10    1300.00    7    7934    4    10    2

 Tags:Sql Server len String function,SQL-Server len String function,SQL-Server 2012 Len String function,How to find String length in SQL-Server,number of characters occupied by String in SQL-Server. Find String Length in SQL-SERVER.

No comments:

Post a Comment