Monday, January 28, 2013

Len in t-SQL/Length of the Column

Len in  t-SQL/Find Length of the Column

Len is a T-SQL String function, displays number of characters in the Column/String variable.

ex:  Find Length of the column

select Len(Description)  from Textbook


Eample 2:

Find Variables Length

 Declare an variable @desc of nvarchar(max)  set some data, and find the length of the string.

declare @desc nvarchar(max);

set @desc=

'New York (Listeni/nuː ˈjɔrk/; locally IPA: [nɪu ˈjɔək]) is a state in the Northeastern region of the United States. New York is the 27th-most extensive, the 3rd-most populous, and the 7th-most densely populated of the 50 United States. New York is bordered by New Jersey and Pennsylvania to the south, and by Connecticut, Massachusetts and Vermont to the east. The state has a maritime border with Rhode Island east of Long Island, as well as an international border with the Canadian provinces of Ontario to the west and north, and Quebec to the north. The state of New York is often referred to as New York State to distinguish it from New York City.';

select len(@desc)


Example 3:

FIND length of multiple columns

select Len(concat(firstname,middlename,lastname)) from Customers
select len(concat(title,firstname,lastname)) from Employees  (northwind DB)

Example 4:

Find Length of the Unicode Column

create table unicodeText
(
   text nvarchar(max)
);

go

insert into unicodeText values(N'हम आपके हैं कौन')

SELECT  datalength([text])
  FROM [tempo1].[dbo].[unicodeText]

Tags:FIND length of multiple columns, len in t-sql,
Find Variables Length,Find Length of the column, column length in t-sql
,Find length of the unicode column

No comments:

Post a Comment