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 + expressionSubtraction
-
Subtracts the second numeric expression from the first.
expression - expressionMultiplication
*
Multiplies two numeric expressions.
expression * expressionDivision
/
Divides the first numeric expression by the second.
expression / expressionModulo
%
Returns the remainder of the division of the first numeric expression by the second.
expression % expressionComparison Operators
Used to compare two expressions. They return a Boolean value (TRUE, FALSE, or UNKNOWN).
Equal To
=
Checks if two expressions are equal.
expression = expressionNot Equal To
<> or !=
Checks if two expressions are not equal.
expression <> expressionGreater Than
>
Checks if the first expression is greater than the second.
expression > expressionLess Than
<
Checks if the first expression is less than the second.
expression < expressionGreater Than or Equal To
>=
Checks if the first expression is greater than or equal to the second.
expression >= expressionLess Than or Equal To
<=
Checks if the first expression is less than or equal to the second.
expression <= expressionLIKE
LIKE
Searches for a specified pattern in a column. Supports wildcard characters ('%' for zero or more characters, '_' for a single character).
expression LIKE patternIN
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 value2IS NULL
IS NULL
Checks if an expression is NULL.
expression IS NULLIS NOT NULL
IS NOT NULL
Checks if an expression is not NULL.
expression IS NOT NULLLogical Operators
Used to combine conditional statements or negate them.
AND
AND
Combines two Boolean conditions. Returns TRUE if both conditions are TRUE.
condition AND conditionOR
OR
Combines two Boolean conditions. Returns TRUE if at least one condition is TRUE.
condition OR conditionNOT
NOT
Reverses the Boolean value of a condition. Returns TRUE if the condition is FALSE.
NOT conditionBitwise Operators
Operate on individual bits of integer data types.
Bitwise AND
&
Performs a bitwise AND operation on two integer expressions.
expression & expressionBitwise OR
|
Performs a bitwise OR operation on two integer expressions.
expression | expressionBitwise XOR
^
Performs a bitwise XOR operation on two integer expressions.
expression ^ expressionBitwise NOT
~
Performs a bitwise NOT operation on an integer expression.
~ expressionLeft Shift
<<
Shifts the bits of the first integer expression to the left by the number of positions specified by the second integer expression.
expression << expressionRight Shift
>>
Shifts the bits of the first integer expression to the right by the number of positions specified by the second integer expression.
expression >> expressionAssignment 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 + string2String Concatenation (ANSI Standard)
||
Concatenates two string expressions (behavior may vary based on SQL Server version and compatibility level).
string1 || string2Other Operators
Concatenation Assignment
+=
Appends the expression on the right to the string variable on the left.
SET @string_variable += expression;