Comparison Operators – Part 1

I am going to keep the ball rolling with my series of very short articles or tidbits on Transaction SQL Operators. An operator is a symbol specifying an action that is performed on one or more expressions.

I will exploring the Comparison Operators today.

These comparison operators are known as the less than <, less than or equal to <=, equal to =, greater than >, and greater than or equal to >= symbols in inequality and equality mathematics.

There are both ANSI standard and Microsoft specific comparison operators. I will be using the tiny integer data type to declare variables in the examples below. This allows us to focus just on the comparison logic instead of worrying about data types and implicit data type conversions.

Each example below shows both a positive and negative test using each ANSI standard operator.

The output of each comparison is listed below.

The TSQL examples below shows one correct use of each Microsoft specific comparison operator.

I suggest not using them in coding since your code will not be portable between different database engines.

The output of each comparison is listed below.

Next time, I will be using comparison operators with different data types.

Related posts

Leave a Comment