Home Forums Programming General Cte for String in random order RE: Cte for String in random order

  • peter.cox (6/27/2014)


    hi

    anyone got an idea for a CTE that takes a string, and puts it into a table with the words in any order.

    so the variable would be 'tesco mixed fruit'

    and the data column in the table would be

    tesco mixed fruit

    mixed fruit tesco

    fruit tesco mixed

    mixed tesco fruit

    fruit mixed tesco

    tesco fruit mixed.

    easy enough to split - which I'd thought was the requirement! - but it's taken on a new level of complexity...

    thanks

    Now that you have a couple of possible solutions, why do you need to do this? What's the business reason?

    p.s. That WHILE loop cleverly disguised as a recursive CTE probably isn't the best idea for a splitter.

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