Previous Topic

Next Topic

Inhoudsopgave

Book Index

Char_length / Len

char_length( ‘character expression’ ) / len( ‘character_expression’ )

Returns the number of characters in a character expression or column.

Example

declare @Var varchar(10), @Fixed char(10)

set @Var = 'snow' + char(32) -- char(32) is the space symbol

set @Fixed = 'snow'

select len( @Var ) as VarLength, len( @Fixed ) as FixedLength

Difference

In ASE the functions ‘char_length’ and ‘len’ are the same. MS SQL Server only has the function ‘len’.

In ASE the function ‘len’ counts trailing spaces. In MS SQL Server trailing spaces are not counted. An unexpected result is that in ASE, the empty string has length one. The reason is that an empty string in ASE is implemented as one space.

In ASE the resulting VarLength is 5 and the FixedLength is 10, whereas in MS SQL Server both the VarLength and the FixedLength are 4.