• Ah, it wasn't clear in the first post this is all dynamic SQL.

    Try wrapping this in a transaction

    exec sp_executesql @s-2

    "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