• Try to rewrite this join.

    Using such constructions in joins, especially when OR is involved is asking for trouble.

    Try something like this:

    ...

    left join objectA

    on objectA.ID = case

    when worktbl.order = 1000 then worktbl.anotherid

    When worktbl.order > 1000 then worktbl.id

    End

    left join

    ....

    But the best way to improve the query performance would be fixing the table design.

    I don't think using conditional JOIN conditions would improve the performance. I suggest you try using UNION (ALL) as an alternative:

    LEFT JOIN objectA

    ON objectA .ID = worktbl.anotherid

    AND worktbl.order = 1000

    ...

    UNION

    ...

    LEFT JOIN objectA

    ON objectA .ID = worktbl.anotherid

    AND worktbl.order > 1000

    Read on Dwain Camps' How to Avoid Conditional Join


    The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url]

    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs[/url]