[SOLVED] SQL PERFORMANCE – alternative to OR statement


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:

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

Answered By – LSerni

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *