• Kay ,

    You are absolutely correct , any solution that relies upon a tally table has to have at least the required number of rows in the said tally table.

    If you used a tally table to build all the dates for the next 10 years, you need to ensure that you have at least 3655 (ish) rows.

    An alternative to your distinct method would be to grab the max(age) , which will involve reading a single row from the index. Something like this...

    with cteTally

    as

    (

    select number from master..spt_values where type = 'P' and number >0 and number <=(Select max(age) from #RunnersBig)

    )

    select *

    from cteTally

    cross apply

    (

    select top 2 * from #RunnersBig where age=number order by time

    ) as Winners



    Clear Sky SQL
    My Blog[/url]