• Hi ,

    Just in case you are interested.

    If you have a numbers/tally table in your database which is always good to have.

    Here is an alternate to your split function that does not require a loop.

    CREATE FUNCTION dbo.Split

    (

    @ItemList NVARCHAR(4000),

    @delimiter CHAR(1)

    )

    RETURNS @IDTable TABLE (Item VARCHAR(50))

    AS

    BEGIN

    INSERT INTO @IDTable

    SELECT SUBSTRING(@ItemList+@delimiter, N,

    CHARINDEX(',', @ItemList+@delimiter, N) - N)

    FROM dbo.Tally

    WHERE N <= LEN(@ItemList)

    AND SUBSTRING(@delimiter + @ItemList,

    N, 1) = @delimiter

    ORDER BY N

    RETURN

    END

    Thanks

    Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life