Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Order Of evaluation in OR'ed subclauses

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-12 : 18:50:54
EveryNanoSecondCounts! writes "Hey, if I have a SELECT inside an SP kind of like this:

CREATE PROC spThisAndThatSel ( @PMatch VARCHAR ) AS

SELECT This, That, ThenSome
FROM SOMETABLE
WHERE (This = @PMatch OR @PMatch IS NULL)

then, if the value of @PMatch is indeed NULL, would evaluation be faster if I put the @PMatch first (@PMatch IS NULL OR This = @PMatch), or will the optimizer realize that it doesn't need to evaluate the WHERE clause ?

Thanx!"

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2006-09-12 : 19:57:56
The order of evaluation is not defined by how you write your query. The optimiser will decide that for you. I remember a few months ago there was another topic on this trying to do short circuit evaluation and someone proved it can sometimes change the order of evaluation.
Go to Top of Page
   

- Advertisement -