CREATE FUNCTION funSplit
(
@Delimiter VARCHAR(5),
@StringValue VARCHAR(8000)
)
RETURNS @TableOfValues TABLE
(
RowID SMALLINT IDENTITY(1,1),
[Value] VARCHAR(150)
)
AS
BEGIN

DECLARE @LenString INT

WHILE LEN( @StringValue ) > 0
BEGIN
SELECT @LenString = (CASE CHARINDEX(@Delimiter, @StringValue) WHEN 0 THEN LEN(@StringValue )
ELSE (CHARINDEX(@Delimiter,@StringValue) -1) END)

INSERT INTO @TableOfValues SELECT SUBSTRING(@StringValue, 1, @LenString)

SELECT @StringValue = (CASE (LEN(@StringValue) - @LenString) WHEN 0 THEN ''
ELSE RIGHT(@StringValue,LEN(@StringValue) - @LenString - 1 ) END)
END

RETURN

END