• Gianluca Sartori (7/12/2010)


    I think this problem could be solved much better with a CLR aggregate, but it's a technique I don't master.

    A CLR aggregate wouldn't be the right choice because an aggregate only returns one row from multiple rows of input. What we need to do here is return multiple rows (the combinations) from a single row input (the multi-delimited string). For that, we need a streaming CLR table-valued function.

    Using the table and sample data kindly provided by pmcpherson, the full solution becomes:

    SELECT TT.TblID, GC.combination

    FROM #TmpTbl TT

    CROSS

    APPLY dbo.GetCombinations(TT.MultiDelimStr) GC;

    It is extremely fast and quite neat. The source code and binary will follow in my next post.

    Paul