• Blurgh, sick in my mouth a little.

    Im no sql purist by any means, but this *cant* work. ie relying on top 100 percent to order ,(at least in the long term)

    Consider these two queries....

    select *

    from (Select 1 as rown) a

    right join (

    select top(100) percent object_id,name

    from sys.objects order by name

    ) as b on a.rown<>b.object_id

    go

    select *

    from (Select 1 as rown) a

    right join (

    select top(99.99) percent object_id,name

    from sys.objects order by name

    ) as b on a.rown<>b.object_id

    Look at the plans, the top 100 percent make so little sense it gets optimized out and the results come back in a 'random' order, or at least in SQL 2012 it does.

    Ordering within SQL can and should only be applied to the final result set.

    There is a 'fix' ( i hate to use that word for this issue ) in 2008

    http://support.microsoft.com/kb/926292

    At the back of my mind i think there may even be a trace flag to enable this too ( im sure someone will correct me if wrong)



    Clear Sky SQL
    My Blog[/url]