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 2005 Forums
 Transact-SQL (2005)
 OR operator

Author  Topic 

laailalalaa
Yak Posting Veteran

57 Posts

Posted - 2010-05-09 : 14:34:07
i know the following is true in many programming languages, please confirm whether this also applies to t-sql:

IF condA OR condB OR condC
THEN ...

condC will be evaluated only if both condA and condB fail, right?

thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-05-09 : 15:19:25
It depends on what the boolean checks are.
SQL Server treats all operators in terms of costs. In you example, SQL Server may very well try condC first!



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

laailalalaa
Yak Posting Veteran

57 Posts

Posted - 2010-05-09 : 15:24:05
got it, thanks Peso
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-05-09 : 15:27:43
It is not equivalence?

IF condA
--THEN
ELSE
IF CondB
--THEN
ELSE
IF CondC
--THEN
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-05-10 : 01:27:10
No.

If condA is considered more costly to evaluate, condC may be evaluated first. Or condB. And condA last.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-05-10 : 06:14:19
Thanks Peso,
Could you please give me a link for reference for this subject?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-05-10 : 13:11:01
Here is some information about cost based
http://www.qdpma.com/SQLServerCostBasedOptimizer.html



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-05-10 : 14:38:40
Thanks, but link do not word for me. Not implortant
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-05-14 : 00:40:20
quote:
Hi,
You already posted about cost based.
I want to know WHEN clauses in CASE are evaluated in order or not?
In a CASE statemnt, the clauses are always evaluated in the order they are written, until one is found true.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -