Returns the number of characters in an expression.
char_length(char_expr | uchar_expr)
select char_length(notes) from titles where title_id = "PC9999"
----------- 39
declare @var1 varchar(20), @var2 varchar(20), @char char(20) select @var1 = "abcd", @var2 = "abcd ", @char = "abcd" select char_length(@var1), char_length(@var2), char_length(@char)
----------- ----------- ----------- 4 8 20
Compressed large object (LOB) columns, char_length returns the number of original plain text characters.
Variable-length columns and variables, char_length returns the number of characters (not the defined length of the column or variable). If explicit trailing blanks are included in variable-length variables, they are not stripped. For literals and fixed-length character columns and variables, char_length does not strip the expression of trailing blanks (see Example 2).
select char_length(ut) from unitable ------------ 4
Multibyte character sets, the number of characters in the expression is usually fewer than the number of bytes; use datalength to determine the number of bytes.
Unicode expressions, returns the number of Unicode values (not bytes) in an expression. Surrogate pairs count as two Unicode values.
If char_expr or uchar_expr is NULL, char_length returns NULL.
See also Transact-SQL Users Guide.
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute char_length.