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 WHERE condition

Author  Topic 

Henrik Svensson
Starting Member

25 Posts

Posted - 2006-02-02 : 04:18:42
Hello!

I have a question concerning SQL Server 2000.

On http://www.sql-server-performance.com/transact_sql_where.asp
it's stated that:

"If you have a WHERE clause that includes expressions connected by two or more AND operators, SQL Server will evaluate them from left to right in the order they are written."

1) Is this correct?
2) Would I interpret this as if the order of my conditions really does matter, even though, for example, my fourth AND-condition is covered by an index, and the preceding aren't? I guess that the query optimizer wouldn't agree.
3) And If I misinterpret the statement above, in what situations does the order of the WHERE-conditions matter?

Thanks in advance.


With best regards,
Henrik Svensson

-----
"Rhubarb, that is Barbapapa backwards. It's called a palindrome."

nr
SQLTeam MVY

12543 Posts

Posted - 2006-02-02 : 10:57:59
1) no
3) Should never matter unless you use a forceplan hint maybe - you should separate or's with parentheses but apart from that the optimiser will decide how to process.
Saying that the optimiser sometimes does odd thnigs.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -