• dwain.c (3/6/2014)


    There's no reason to call DelimitedSplit8K twice, even if it is super-efficient (bless its heart):

    WITH SampleData (s) AS

    (

    SELECT 'XYZ00001|Test_b|XYZ00002|Test_a|XYZ00003|Test_c'

    )

    SELECT s

    ,Col1=MAX(CASE WHEN ItemNumber%2 = 1 THEN Item END)

    ,Col2=MAX(CASE WHEN ItemNumber%2 = 0 THEN Item END)

    FROM SampleData

    CROSS APPLY dbo.DelimitedSplit8K(s, '|')

    GROUP BY s, (1+ItemNumber)/2;

    +1000 Excellent.

    --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)