Click here to Skip to main content
15,939,736 members
Please Sign up or sign in to vote.
4.67/5 (3 votes)
See more:
I know the order of conditions is important in at least C and C#. For example, the two following conditions are different:
1. (str1.Length > 0&&str1[0] == 'A')
This works well and is the correct one.
2. (str1[0] == 'A'&&str1.Length>0)
This is too ridiculous because the order of executing commands (in this case) is from left to right, if str1.Length = 0, an exception will be thrown, so it can't work. This is only a simple example. But what I want to know is Do SQL queries work the same way with conditions after WHERE, HAVING, ON or anywhere else possible?
Thank you so much!
Posted

1 solution

Do you want the bad news? Sorry, but SQL does not behave the same as C, C++ and C#. In those, AND clauses are always executed left - to right, and any false result will abort the operation (called "evaluation short-circuiting"). SQL does not do that. What it does do is more complex. There is a description here: How SQL Server short circuits WHERE condition evaluation[^]

Gets my five for a very good question, though!
 
Share this answer
 
Comments
[no name] 19-Apr-11 7:48am    
Thank you so much!
I also give you my 5.0!
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900