• Jeff Moden (3/25/2015)


    dwain.c (3/25/2015)


    Jeff Moden (3/24/2015)


    Will there only ever be two "id_fixing" values? If not, how many are there or could be?

    I hate it when you ask questions like that. Makes me think I overlooked something obvious.

    My solution assumes you could have as many as you want.

    As Itzik pointed out in his post, his code isn't optimized (but it sure does give food for thought). Prior to seeing that, this looked to me like a temporal bin stacking problem. It seemed to me that it might be simpler to attack the problem horizontally than vertically but to do that without dynamic SQL, there needs to be a fixed number of horizontal bins and that's why I wanted to know if there were only 2 id_Fixing values.

    Of course, Marco took Cadavre's datapost to another forum, hasn't replied back here, got an answer from Itzik that does work (even if it isn't optimized with a 57 read work table and a bit of a cross join), and didn't say thanks or anything. Itzik's sort on the Product table is where I had gotten to just by playing with the setup but stopped for the id_Fixing question. I'll save the problem as an intellectual curiosity for later on when I'm not so hammered by work.

    I thought it was a bin-packing problem too at first, hence why I thought it couldn't be done without a loop.

    Interesting that a new post just popped up with nearly the same requirement:

    http://www.sqlservercentral.com/Forums/Topic1671558-3077-1.aspx


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St