1
WHERE ConditionA OR ConditionB OR ConditionC

Does it execute ConditionB or ConditionC if ConditionA is true?

EDIT

Here is the actual condition which in a TVF. I want to make sure whether my complex query is not executing if MustNotHaveAllConditions is null or empty.

@MustNotHaveAllConditions = '' OR @MustNotHaveAllConditions IS NULL OR
Patient.Id NOT IN 
( ... complex sql query
)
  • Give the full example code. Did you check the query plan? – ThomasMcLeod Dec 15 '11 at 01:48
  • Can you clarify your question? Are you asking what result set will be returned, or are you asking if the Sql Engine actually executes the condition to check if the condition is true if the first condition already is true? – mservidio Dec 15 '11 at 01:48
  • So if A is true and C is true you will get back records for A and C. – The Muffin Man Dec 15 '11 at 01:48
  • @ThomasMcLeod: query plan does not specify this – zerkms Dec 15 '11 at 02:01
  • Is `@MustNotHaveAllConditions` logically independent of the `NOT IN` subquery or is one dependent on the other in some way? – ThomasMcLeod Dec 15 '11 at 02:50
  • This question apparently has been asked and answered: http://stackoverflow.com/questions/789231/is-the-sql-where-clause-short-circuit-evaluated. The consensus seems to be that short-circuit evaluation is not guaranteed in SQL Server. – ThomasMcLeod Dec 15 '11 at 03:00

1 Answers1

3

No. But make sure that in some cases optimizer could change the operands order

zerkms
  • 249,484
  • 69
  • 436
  • 539