• chaseurpuli (9/6/2012)


    Thanks a lot for your response Dwain. Your code is successful in keeping the families together and ordering the items by date as long as the parents have different dates. But when two or more parents have same date, it has failed in keeping the families together. It is ordering the parents with same date first and then their childs next.

    In our example, if we change the Item 5's date as '2012-08-07' (same as item 2) then the results are:

    ItemID Date

    2 2012-08-07 00:00:00.000

    5 2012-08-07 00:00:00.000

    1 2012-09-08 00:00:00.000

    3 2012-09-09 00:00:00.000

    4 2012-09-10 00:00:00.000

    You are correct! Sorry about that.

    Since MickyT's seems to work, I assume you'll proceed with that.


    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