• You've got nested functions and you're accessing large amounts of data? That's a major design flaw. The only way to improve performance is back out of the use of multi-statement table valued functions and start addressing the T-SQL directly. The inline functions might be a good idea, but don't nest them. Otherwise, regular T-SQL queries are usually the best approach. If you really need to break down the code, which is a valid approach at times, then use temporary tables because they will provide statistics making queries that JOIN them or search against them more efficient.

    Also, one suggestion involved the NO_LOCK hint. I'm very wary of hints in general, but the NO_LOCK hint in particular is especially dangerous. Understand it thoroughly before you apply it.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning