• _ms65g_ (5/20/2010)


    In splitting string using number table is not this approch simpler?

    DECLARE @s-2 VARCHAR(80)='Army,Navy,Air Force,Marines'

    ;WITH c AS

    (SELECT 1 AS n

    UNION ALL

    SELECT n+1 FROM c WHERE n < 100)

    SELECT i

    FROM (SELECT CASE WHEN CHARINDEX(',', @s-2 + ',', n) - n = 0 THEN ''

    ELSE SUBSTRING(@s, n, CHARINDEX(',', @s-2 + ',', n) - n)

    END, n

    FROM c

    WHERE n <= LEN(@s)

    ) d(i, n)

    WHERE SUBSTRING(',' + @s-2, n, 1) = ','

    Sorry... got pulled away on other things...

    Yes... that method is much "simpler". It's also much slower in the grand scheme of things because recursive counters are as bad or worse than While Loops for performance and they use a lot more "reads" even if the reads are in memory.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)