There are several SQL split functions, from loop driven, to using xml commands, and even using a numbers table. I haven\'t found one that supports text qualifiers.
Usin
This is a quick solution, and it is less than perfect, it has no stack, so it will treat the comma inside the quotes as the delimiter.
alter function fnSplit
(
@Delim char(1),
@List nvarchar(4000)
)
returns table as
return
with
Strings(PosIdx) as
(
select 1
union all
select PosIdx + 1 from Strings where PosIdx < 4000
)
select
ltrim(rtrim(substring(@List, PosIdx, charindex(@Delim, @List + @Delim, PosIdx) - PosIdx))) as value
from
Strings
where
PosIdx <= convert(int, len(@List))
and substring(@Delim + @List, PosIdx, 1) = @Delim
go
select * from fnSplit(',', 'jsmith@anywhere.com, "Sally \"Heat\" Jones" , "Mark Jones" , "Stone, Ron" ')
option (maxrecursion 0)