Databases Reference
In-Depth Information
Table 6-1: Arithmetic and Concatenation Operators
Operator
Description
Addition: adds two numbers. When used with SQL Server,
also concatenates (joins together) strings. The use for
concatenation in nearly unique to SQL Server.
Subtraction: subtracts one numeric value from another.
*
Multiplication: multiplies one number by another.
/
Division: divides one number by another.
%
Modulo: calculates the integer remainder of a division.
For example, 15%5 0, 17%5 2, 18%5 3, and 20%5 0
This gives you the following result, with “total_value” used as the column name.
total_value
10
To concatenate (join together) numbers in SQL Server, you would need to
use a different expression. Instead of numeric data, you would use numbers rep-
resented as strings. Use the operator with values that are explicitly identified
as strings, as in the following:
SELECT '5'
'5' total_value
This gives you the result:
total_value
55
6.3.2 Comparison and Logical Operators
You can use comparison operators in a SELECT statement's WHERE clause or
with decision statements that take an action depending on the logical result of
a comparison operation, such as: “If A B, then perform an action.” The most
commonly supported comparison operators are listed in Table 6-2.
Some DBMS vendors recommend that whenever possible, you should avoid
negated operators because they require more resources to process. For example,
a query using will run faster than a query using ! .
Comparison operators can be used by themselves or together with logical
operators. Logical operators are used to evaluate a set of conditions, with the
returned result a value of TRUE, FALSE, or “unknown.” Like comparison operators,
you can use logical operators in a SELECT statement's WHERE clause or with
Search WWH ::




Custom Search