OR (Transact-SQL)
Combines two conditions. When more than one logical operator is used in a statement, OR operators are evaluated after AND operators. However, you can change the order of evaluation by using parentheses.
Transact-SQL Syntax Conventions
Syntax
boolean_expression OR boolean_expression
Arguments
- boolean_expression
Is any valid expression that returns TRUE, FALSE, or UNKNOWN.
Remarks
The following table shows the result of the OR operator.
TRUE | FALSE | UNKNOWN | |
---|---|---|---|
TRUE |
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
FALSE |
UNKNOWN |
UNKNOWN |
TRUE |
UNKNOWN |
UNKNOWN |
Result Types
Boolean
Result Value
OR returns TRUE when either of the conditions is TRUE.
Examples
The following example uses the vEmployeeDepartmentHistory
view to retrieve the names of Quality Assurance
personnel who work either the evening shift or the night shift. If the parentheses are omitted, the query returns Quality Assurance
employees who work the evening shift and all employees who work the night shift.
USE AdventureWorks
GO
SELECT FirstName, LastName, Shift
FROM HumanResources.vEmployeeDepartmentHistory
WHERE Department = 'Quality Assurance'
AND (Shift = 'Evening' OR Shift = 'Night')
Here is the result set.
FirstName LastName Shift
------------ ---------------- -------
Andreas Berglund Evening
Sootha Charncherngkha Night
See Also
Reference
Expressions (Transact-SQL)
Functions (Transact-SQL)
Operators (Transact-SQL)
SELECT (Transact-SQL)
WHERE (Transact-SQL)
Other Resources
Help and Information
Getting SQL Server 2005 Assistance
Change History
Release | History |
---|---|
14 April 2006 |
|