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.