SPLIT
Splits a string around a java-style regular expression.
Syntax
SPLIT ( 'string', 'regexp' [, index] )
Arguments
'string'
Is an expression of any character type (i.e. nvarchar, varchar, nchar or char).
'regexp'
Is a Java-style regular expression of any character type that is used around 'string'.
[index]
Optional index of result you want to return. If no index value is specified, regexp results are returned as a string separated by single character '|' (pipe).
Example
Splits values from column "s" using different regular expressions and returns results using result index:
select split([s], '[AB]', 0) as a , split([s], '[ABC]', 1) as b , split([s], '[ABC]', 2) as c from ( select 'abaAbbbBccC' as s union all select 'aaaAbbbBcCc' union all select 'oneAtwoBthreeC' ) as dat
Result:
a b c ----- ----- ---- aba bbb cc aaa bbb c one two three