Previous Topic

Next Topic

Inhoudsopgave

Book Index

SubString

SubString( character_expression, start, length )

Returns the part of character_expression starting at the position start for length characters.

Example

select SubString( 'abcde', 3, 2 )

Differences

If ‘start’ ≤ 0 or if ‘start’ is larger than the length of character_expression, ASE returns NULL. Remember that in ASE the NULL string is treated as the empty string in MS SQL Server. In MS SQL Server, if the ‘start’ ≤ 0, the length of the resulting string is smaller than ‘length’. All positions up to position 1 count as an empty string.

 

ASE

MS SQL Server

SubString( 'abcde', 2, 3 )

'bcd'

'bcd'

SubString( 'abcde', 1, 3 )

'abc'

'abc'

SubString( 'abcde', 0, 3 )

NULL

'ab'

SubString( 'abcde', −1, 3 )

NULL

'a'

If ‘start’ is larger than the length of character_expression, MS SQL Server returns the empty string, whereas ASE returns the NULL string. Remember, however, that the NULL string in ASE behaves like the empty string.

Finally, if ‘character_expression’ equals NULL, ASE returns NULL, whereas MS SQL Server returns an error message.