aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT, Building Your First Web Application Project
Advertise Here

Toolbar

Get our toolbar!

Advertize



Posted by Aamir Hasan   on Friday, May 27, 2011 Total Views:  

In this example, you will see how to get the length of a string in T-SQL. Len function returns the numeric. Len function is used to get the length. Len function can be used in SELECT query. Len function takes only one argument

Here’s is an example

CREATE   TABLE PATIENT

    (

      ID BIGINT IDENTITY,

      FULLNAME VARCHAR(100),

      GENDER CHAR,

      DESCRIPTION NVARCHAR(MAX),

      DETAILS TEXT

    )

 

GO

 

INSERT INTO PATIENT

VALUES('AAMIR HASAN','M','--','EMPTY'),

('AWAIS AHMED','M','-','EMPTY'),

('MAHWISH IKTAR','M','--','EMPTY'),

('BILAL AHMED','F','---',NULL),

('SABA KHAN','F','----','-')

GO

SELECT  *

FROM    PATIENT

 

Example 1

 

SELECT  LEN(FULLNAME) AS [FULLNAME LEN],

        LEN(DESCRIPTION) AS [DESCP],

        *

FROM    PATIENT


Output

 

Example 2

 

SELECT  LEN(FULLNAME) AS [FULLNAME LEN],

        LEN(DETAILS) AS [DESCP],

        *

FROM    PATIENT

 

Output

 

Msg 8116, Level 16, State 1, Line 1

Argument data type text is invalid for argument 1 of len function.

When you will try to get the Len of text field column you will always see the error message as shown above.

 

Note: Len function will not work for text field.

 

Protected by Copyscape Online Plagiarism Tool

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5