Home Forums SQL Server 2008 T-SQL (SS2K8) Change Set clause of Update Statement dynamically based on some condition. RE: Change Set clause of Update Statement dynamically based on some condition.

  • Since this is two completely different statements, assuming we're putting this into a stored procedure, why not create two stored procedures? You're looking at the need for two different execution plans (two different WHERE clauses) so it's going to be two different statements within SQL Server. You're doing a ton of work to create a dynamic statement only to arrive at the same place you'd be if you had two statements. Just go for two statements. Simpler solutions are usually the more elegant. You're also going to have more tuning opportunities with multiple statements (or certainly, easier tuning opportunities). Having two procedures doesn't hurt SQL Server or your table. I just don't see the benefit of building this out in this fashion.

    "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