• First of all Wayne, this is a great primer on using the new SQL 2012 analytic functions, and I know I for one will be referring folks to it if they have any questions.

    RichB (1/19/2012)


    Any idea what the performance of these things is like?

    I can comment on using LAG (vs. LEAD) to calculate gaps. I did a recent test on a 1M row test harness (partitioned sets) and came up with the following results.

    MEDIAN CPU (ms) Elapsed (ms)

    SQL 2012 LEAD 1747 1740

    SQL 2012 LAG 1357 1363

    I am not sure why LAG works faster than LEAD but it seemed to be consistent. Neither of them is overall elapsed time winner compared to other solutions I've tried.


    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