Previous Topic

Next Topic

Inhoudsopgave

Book Index

CharIndex

CharIndex( ‘character_expression_1’, ‘character_expression_2’)

Searches the second expression for the first occurrence of the first expression and returns the integer representing its starting position, or 0 if it is not found.

Example

select CharIndex( 'cd', 'abcde' )

Difference

MS SQL Server handles NULL arguments according to the ANSI rules. ASE treats NULL strings as if they were empty strings. Also, because in ASE the empty string is implemented as a string containing one space, there is a difference in behavior when empty strings are used as arguments.

 

ASE

MS SQL Server

CharIndex( NULL, 'abc' )

0

NULL

CharIndex( 'a', NULL )

0

NULL

CharIndex( '', '' )

1

0

CharIndex( Char(32), '' )

1

0

Note: For both systems, the result of CharIndex( NULL, NULL ) is NULL.