Comparison Search Conditions

Microsoft® SQL Server™ uses these comparison operators.

Operator Meaning
= Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
< > Not equal to (SQL-92 compatible)
!> Not greater than
!< Not less than
!= Not equal to

Comparison operators are specified between two expressions. For example, to retrieve the names of only those products for which the unit price is greater than $50, use:

SELECT ProductName

FROM Northwind.dbo.Products

WHERE UnitPrice > $50.00

When you compare character string data, the logical sequence of the characters is defined by the sort order specified during SQL Server Setup. The result of comparison operators such as < and > are controlled by the character sequence defined in the sort order. For Unicode columns, the results of comparison operators are controlled by the Unicode collation order specified during the Setup program. (For more information about specifying sort orders and Unicode collation orders during installation, see Sort Order and Unicode Collation.)

Trailing blanks are ignored in comparisons in non-Unicode data; for example, these are equivalent:

WHERE au_lname = 'White'

WHERE au_lname = 'White '

WHERE au_lname = 'White' + SPACE(1)

  

The use of NOT negates an expression. For example, this query finds all products that do not have a unit price over $50, which is logically the same as asking for all products that have a unit price of $50 or lower:

SELECT ProductID, ProductName, UnitPrice

FROM Northwind.dbo.Products

WHERE NOT UnitPrice < $50

ORDER BY ProductID

  

See Also
String Concatenation Operator Sort Order
+ (String Concatentation) Data Types
Operators  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.