I am trying to optimize this sql query and I see it's using tons of OR statements throughout it, particularly again and again with the same parameter. I see if I comment out the heaviest use of it, execution time reduces by 150%.
the part I commented out looks like this for example:
declare @variable bit = 1
select 1 where @variable = 1 or not exists(select 1 where 1 = 2)
can anyone suggest a way to rewrite this without the OR ?
I am using Sql Azure
It is not very clear what your query does - you simplified it too much - but you could try: