SqlExpression POSITION
From Eigenpedia
Contents |
Syntax
POSITION( search_substring IN source_string)
Purpose
Returns the position of a substring within a string as an integer value. The beginning of a string starts at 1.
Input
- search_substring [VARCHAR] - the substring to search for
- source_string [VARCHAR] - the string to search within
Output
- [INTEGER] - the first character position of the first occurence of search_string within source_string. The first character in a string is position 1.
- if search_string does not exists within source_string, 0 is returned.
- if search_strin is empty string, 1 is returned
- if either input is null, null is returned
Example
| Function | Result |
|---|---|
| POSITION( 'is' IN 'This is a string is it?' ) | 3 |
| POSITION( IN 'This is a string' ) | 1 |
| POSITION( 'strike' IN 'This is a string' ) | 0 |
| POSITION( 'a' in cast(null as varchar(1)) ) | null |

