SQL PERFORMANCE - alternative to OR statement

618 views Asked by At

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

1

There are 1 answers

1
LSerni On BEST ANSWER

It is not very clear what your query does - you simplified it too much - but you could try:

SELECT ... WHERE condition1
UNION
SELECT ... WHERE condition2