• Jason A. Long (7/2/2015)


    sratemo (7/2/2015)


    Hi Jason,

    Your solution looks solid but the query wouldn't execute past:

    "MAX(adg.AdminDateGroup) OVER (PARTITION BY adg.PatientID ORDER BY adg.AdmissionDate) AS AdminDateGroup".

    error - Incorrect syntax near 'order'.

    Tried going around this but then got discrepancies in the results.

    Yea... That's my bad. I knew that 2008 supported windowed aggregates but it looks like it only supports partitioning, not ordering... So completely my fault on that...

    Luckily Dwain was able to step up to the plate and come up with a good working solution. I haven't had a chance to dig into his code but I definitely will. He's always good at supplying fantastic new tools for the toolbox. 🙂

    Well, that's not exactly a new tool (IBG's approach to collapsing overlapping intervals) but I thank you nonetheless.

    Note that I tried to avoid the extra sub-query I used to pull the cost but I couldn't see a way to make that work within the interval collapsing algorithm. That "magic filter" that IBG came up with seems to preclude doing it in there. Had I been able to, I believe it would have removed the extra INDEX SCAN (or SEEK).


    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