Comparison Search Conditions

Microsoft SQL Server 2005 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 list price is greater than $50, use:

SELECT Name
FROM AdventureWorks.Production.Product
WHERE ListPrice > $50.00

When you compare character string data, the logical sequence of the characters is defined by the collation of the character data. The result of comparison operators such as < and > are controlled by the character sequence defined by the collation. The same SQL Collation might have different sorting behavior for Unicode and non-Unicode data. For more information, see Working with Collations.

Trailing blanks are ignored in comparisons; for example, these are equivalent:

WHERE LastName = 'White'
WHERE LastName = 'White '
WHERE LastName = 'White' + SPACE(1)

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

SELECT ProductID, Name, ListPrice
FROM AdventureWorks.Production.Product
WHERE NOT ListPrice < $50
ORDER BY ProductID

See Also

Concepts

String Concatenation Operator (Database Engine)

Other Resources

+ (String Concatenation) (Transact-SQL)
Data Types (Transact-SQL)
Operators (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance