Other solutions for same task(you may create a function out of this):
1:
declare
@pString VARCHAR(7999)='asdfasdf-asddf- -wer-we',
@pDelimiter CHAR(1) = '-'
;with a(N) as
(
select 1
union all
select N+1 from a
where N < 10000
)
SELECT
ItemNumber = ROW_NUMBER() OVER (ORDER BY N),
Item = SUBSTRING(@pString, N, CHARINDEX(@pDelimiter, @pString + @pDelimiter, N) - N)
FROM a
WHERE N < LEN(@pString) + 2
AND SUBSTRING(@pDelimiter + @pString, N, 1) = @pDelimiter
option (maxrecursion 32500)
2:
declare
@pString VARCHAR(7999)='asdfasdf-asddf- -wer-we',
@pDelimiter CHAR(1) = '-'
;with a(N) as
(
select N=0
union all
select N=CHARINDEX(@pDelimiter, @pString + @pDelimiter, N+1)
from a
where N < LEN(@pString)
)
, b as
(
select N=a.N, N1=min(b.N)
from a
join a b on b.N > a.N
group by a.N
)
select q=SUBSTRING(@pString,N+1, N1-N-1) from b