Operators

Transact-SQL (T-SQL) operators are symbols or keywords that specify the type of computation or comparison to be performed in an expression.

Arithmetic Operators

Used to perform mathematical calculations.

Addition

+

Adds two numeric expressions.

expression + expression

Subtraction

-

Subtracts the second numeric expression from the first.

expression - expression

Multiplication

*

Multiplies two numeric expressions.

expression * expression

Division

/

Divides the first numeric expression by the second.

expression / expression

Modulo

%

Returns the remainder of the division of the first numeric expression by the second.

expression % expression

Comparison Operators

Used to compare two expressions. They return a Boolean value (TRUE, FALSE, or UNKNOWN).

Equal To

=

Checks if two expressions are equal.

expression = expression

Not Equal To

<> or !=

Checks if two expressions are not equal.

expression <> expression

Greater Than

>

Checks if the first expression is greater than the second.

expression > expression

Less Than

<

Checks if the first expression is less than the second.

expression < expression

Greater Than or Equal To

>=

Checks if the first expression is greater than or equal to the second.

expression >= expression

Less Than or Equal To

<=

Checks if the first expression is less than or equal to the second.

expression <= expression

LIKE

LIKE

Searches for a specified pattern in a column. Supports wildcard characters ('%' for zero or more characters, '_' for a single character).

expression LIKE pattern

IN

IN

Checks if an expression matches any value in a list of values.

expression IN (value1, value2, ...)

BETWEEN

BETWEEN

Checks if an expression is within a range of values (inclusive).

expression BETWEEN value1 AND value2

IS NULL

IS NULL

Checks if an expression is NULL.

expression IS NULL

IS NOT NULL

IS NOT NULL

Checks if an expression is not NULL.

expression IS NOT NULL

Logical Operators

Used to combine conditional statements or negate them.

AND

AND

Combines two Boolean conditions. Returns TRUE if both conditions are TRUE.

condition AND condition

OR

OR

Combines two Boolean conditions. Returns TRUE if at least one condition is TRUE.

condition OR condition

NOT

NOT

Reverses the Boolean value of a condition. Returns TRUE if the condition is FALSE.

NOT condition

Bitwise Operators

Operate on individual bits of integer data types.

Bitwise AND

&

Performs a bitwise AND operation on two integer expressions.

expression & expression

Bitwise OR

|

Performs a bitwise OR operation on two integer expressions.

expression | expression

Bitwise XOR

^

Performs a bitwise XOR operation on two integer expressions.

expression ^ expression

Bitwise NOT

~

Performs a bitwise NOT operation on an integer expression.

~ expression

Left Shift

<<

Shifts the bits of the first integer expression to the left by the number of positions specified by the second integer expression.

expression << expression

Right Shift

>>

Shifts the bits of the first integer expression to the right by the number of positions specified by the second integer expression.

expression >> expression

Assignment Operators

Used to assign values to variables.

Assignment

=

Assigns the value of the expression on the right to the variable on the left.

DECLARE @variable data_type; SET @variable = expression;

Compound Assignment

+=, -=, *=, /=, %=

Combine an arithmetic operation with an assignment.

SET @variable += expression;

String Operators

Used to concatenate or manipulate string data.

Concatenation

+

Concatenates two string expressions.

string1 + string2

String Concatenation (ANSI Standard)

||

Concatenates two string expressions (behavior may vary based on SQL Server version and compatibility level).

string1 || string2

Other Operators

Concatenation Assignment

+=

Appends the expression on the right to the string variable on the left.

SET @string_variable += expression;