17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3: The Foundation Statements of T-<strong>SQL</strong><br />

50<br />

This time we’ve gotten back precisely what we wanted — nothing more, nothing less. In addition, this<br />

query runs much faster than the first query.<br />

Let’s take a look at all the operators we can use with the WHERE clause:<br />

Operator Example Usage Effect<br />

=,<br />

>,<br />

=,<br />

,<br />

!<<br />

AND,<br />

OR,<br />

NOT<br />

= <br />

= ‘Bob’<br />

= AND<br />

>= <br />

!= “MyLiteral”<br />

OR =<br />

“MyOtherLiteral”<br />

Standard comparison operators, these work<br />

as they do in pretty much any programming<br />

language with a couple of notable points:<br />

1. What constitutes “greater than,” “less than,”<br />

and “equal to” can change depending on the<br />

collation order you have selected. (For example,<br />

“ROMEY” = “romey” in places where caseinsensitive<br />

sort order has been selected, but<br />

“ROMEY” < > “romey” in a case-sensitive<br />

situation.)<br />

2. != and both mean “not equal.” !< and !><br />

mean “not less than” and “not greater than,”<br />

respectively.<br />

Standard boolean logic. You can use these to<br />

combine multiple conditions into one WHERE<br />

clause. NOT is evaluated first, then AND, then OR. If<br />

you need to change the evaluation order, you can<br />

use parentheses. Note that XOR is not supported.<br />

BETWEEN BETWEEN 1 AND 5 Comparison is TRUE if the first value is<br />

between the second and third values inclusive.<br />

It is the functional equivalent of A>=B AND<br />

A

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!