char_length

Description

Returns the number of characters in an expression.

Syntax

char_length(char_expr | uchar_expr)

Parameters

char_expr

is a character-type column name, variable, or constant expression of char, varchar, nchar, text_locator, unitext_locator, or nvarchar type.

uchar_expr

is a character-type column name, variable, or constant expression of unichar or univarchar type.

Examples

Example 1

select char_length(notes) from titles
	where title_id = "PC9999"
 -----------
          39

Example 2

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

Usage

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

Any user can execute char_length.

See also

Documentation Transact-SQL Users Guide

Function datalength