Home Forums SQL Server 2012 SQL 2012 - General Grouping and Sorting challenge RE: Grouping and Sorting challenge<!-- 864 -->

  • CELKO (8/21/2014)


    This is one of those places where a loop (please see the solution I posted above) actually does work quite well and it's self correcting based on the number of rows in the two tables. And, remember... I'm one of those that hates loops! 😉

    We are getting into an example of why "set-oriented programming can stink" that us RDBMS (functional, declarative, whatever) do not want to admit. By its nature, set-oriented programming must produce all valid answers.

    That can be a very large set 🙁 An unusably large set. And it the real world we need only one answer to move forward. It does not matter which one, really.

    Remember stable marriages problem? At least one solution must exist. Solutions can favor men or women various degrees. So pick one 😉

    🙂

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