Operators


In the previous section, you were introduced to the use of the & operator. Operators are used in programming languages to aid in the evaluation of expressions. The following table lists operators with which you should become familiar:

Operator

Description

*

The multiplication operator is used when multiplying fields or values.

/

The divide operator is used when dividing fields or values.

The minus operator is used when subtracting fields or values.

>

The greater-than operator is used in WHERE clauses to determine whether a first value is greater than the second, such as:

 SELECT * FROM Employees  WHERE EmployeeID > 10  

 

The result returns all the EmployeeIDs after 10.

<

The less-than operator is used in WHERE clauses to determine whether a first value is less than the second, such as:

 SELECT *  FROM Employees WHERE EmployeeID < 10 

 

The result returns EmployeeIDs 19.

>=

The greater than or equal to operator is used in WHERE clauses to determine whether a first value is greater than or equal to the second, such as:

 SELECT *  FROM Employees WHERE EmployeeID >= 10  

 

The result returns EmployeeIDs of 10 and greater.

<=

The less than or equal to operator is used in WHERE clauses to determine whether a first value is less than or equal to the second, such as:

 SELECT *  FROM Employees WHERE EmployeeID <= 10 

 

The result returns all the EmployeeIDs between 1 and 10.

<>, !=

Used to check whether a value is not equal to a second.

AND

Typically used with the WHERE clause in the SELECT statement. The AND operator returns a second value, such as:

 SELECT *  FROM Employees WHERE EmployeeID = 1 AND EmployeeID = 2 

OR

Typically used with the WHERE clause in the SELECT statement. The OR operator can be used when a certain condition needs to be met or when you can settle for a second, such as:

 SELECT *  FROM Employees WHERE EmployeeID = 1 OR EmployeeID = 2  

LIKE

The LIKE operator is generally used with WHERE clauses when a wildcard needs to be performed, such as:

 SELECT *  FROM Employees WHERE Name LIKE 'A%' 

 

This result returns all employees whose names start with A. Our result returns Ada and Agnes because both their names begin with the letter A.

NOT

Typically used in conjunction with the LIKE operator, the NOT operator is used when a value is not going to be LIKE the value of a second, such as:

 SELECT *  FROM Employees WHERE Name NOT LIKE 'A%' 

 

In this case, all names other than Ada and Agnes are returned.

%

The multiple-character operator is similar to the underscore operator except that it allows for multiple characters, whereas the underscore operator allows for only two. This operator is used in more situations than the underscore operator.

_

The underscore operator is used with WHERE clauses and is performed when you do not know the second value, such as:

 SELECT *  FROM Employees WHERE BillingShippingState LIKE 'A_' 

 

The result, in this case, returns all states that begin with the letter A, such as AK, AL, AR, and AZ.





Macromedia Dreamweaver 8 Unleashed
Macromedia Dreamweaver 8 Unleashed
ISBN: 0672327600
EAN: 2147483647
Year: 2005
Pages: 237
Authors: Zak Ruvalcaba

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net