• Sorry, I did forget to include the splitstring function:

    CREATE function [dbo].[SplitString]

    (

    @str nvarchar(4000),

    @separator char(1)

    )

    returns table

    AS

    return (

    with tokens(p, a, b) AS (

    select

    1,

    1,

    charindex(@separator, @str)

    union all

    select

    p + 1,

    b + 1,

    charindex(@separator, @str, b + 1)

    from tokens

    where b > 0

    )

    select

    p-1 zeroBasedOccurance,

    substring(

    @str,

    a,

    case when b > 0 then b-a ELSE 4000 end)

    AS s

    from tokens

    )

    GO

    Edit BTW, this was probably not original, but if it isn't I'm not sure of the source.

    Be still, and know that I am God - Psalm 46:10