Comparison Operators

Comparison operators contrast a specific difference between two expressions. Comparisons must only be made between variables, columns, and so on, of similar type.

These are the comparison operators:

Symbol Meaning
= Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
< > Not equal to
!= Not equal to (not ANSI standard)
!> Not greater than (not ANSI standard)
!< Not less than (not ANSI standard)

In comparing char and varchar data, < means closer to the beginning of the alphabet and > means closer to the end of the alphabet. In the ASCII collating sequence, lowercase letters are greater than uppercase letters, and uppercase letters are greater than numbers. However, case and special-character evaluations depend on the sorting sequence chosen when SQL Server was installed. For details about sorting sequence, see the Microsoft SQL Server Setup.

In comparing dates, < means earlier and > means later. Place quotation marks around all character and datetime data used with a comparison operator.