SQL OPERATORS AND FUNCTIONS BY AHAMED HASHIR.M
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 1/17
SQL OPERATORS AND FUNCTIONS
BY
AHAMED HASHIR.M
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 2/17
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 3/17
SCALAR FUNCTIONS
` Scalar functions operate on a single value.
` Scalar functions return a single value.
` Scalar functions can be used wherever an expression is valid.
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 4/17
FUNCTION CATEGORY DESCRIPTION
Configuration functions Return information about the current
configuration.
Cursor functions Return information about cursors.
Date and Time Data types and functions Perform operations on a date and time
input values and return string, numeric, or
date and time values.
Mathematical functions Perform calculations based on input
values provided as parameters to the
functions, and return numeric values.
Metadata functions Return information about the database
and database objects.
Security functions Return information about users and roles.
String functions Perform operations on a string (char or
varchar) input value and return a string or
numeric value.
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 5/17
FUNCTION CATEGORY DESCRIPTION
System functions Perform operations and return
information about values, objects, and
settings in an instance of SQL Server.
System Statistical functions Return statistical information about the
system.
Text and Image functions Perform operations on text or image input
values or columns, and return informationabout the value.
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 6/17
AGGREGATE FUNCTIONS
` Aggregate functions perform a calculation on a set of values and return asingle value.
` Aggregate functions are frequently used with the GROUP BY clause of the
SELECT statement.
` Aggregate functions can be used as expressions only in the following:
I. The select list of a SELECT statement.
II. A COMPUTE or COMPUTE BY clause.
III.
A HAVING clause.
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 7/17
FUNCTION DESCRIPTION SYNTAX
AVG The AVG Function returns the
average value for the column.
AVG(column)
COUNT The COUNT Function Returns
the number of rows (without
a NULL value) of a column
Returns the number of
selected rows
Returns the number of rows
where the specified columnhas a distinct, non-NULL value.
COUNT(column)
COUNT(*)
COUNT(distinct column name)
SUM The SUM Function returns the
sum of all values in the
specified column.
SUM(column)
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 8/17
FUNCTION DESCRIPTION SYNTAX
MAX Returns the highest value
of a column
MAX(column)
MIN The MIN Function returns
the data item with the
lowest value for acolumn.
MIN(column)
FIRST Returns the value of the
first record in a specified
field (not supported in
SQLServer2K)
FIRST(column)
LAST Returns the value of the
last record in a specified
field (not supported in
SQLServer2K)
LAST(column)
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 9/17
ROWSET FUNCTIONS
` The following row set functions return an object that can be used in placeof a table reference in a Transact-SQL statement.
CONTAINSTABLE
OPENQUERY
FREETEXTTABLE
OPENROWSET
OPENDATASOURCE
OPENXML
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 10/17
RANKING FUNCTIONS
` Ranking functions return a ranking value for each row in a partition.Depending on the function that is used, some rows might receive the samevalue as other rows.
` Ranking functions are nondeterministic.
` Ranking functions are as follows:
RANK
NTILE
DENSE RANK
ROW_NUMBER
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 11/17
SQL OPERATORS
` The SQL operators can be classified as
` COMMON OPERATORS
` LOGICAL OPERATORS
` MATHEMATICAL OPERATORS
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 12/17
COMMON OPERATORS
OPERATOR DESCRIPTION SYNTAX
; - semicolon Semicolon is used whentwo SQL commands must
be separated
;
* - "star" Is an alias for all fields of the selected table. *
ALL ALL is used to select allrecords of an SELECT
statement.
ALL [ ( SELECT-command )]
ANY ANY is used to apply alogical construct to all
records at the right side of the operator.
ANY[ ( SELECT-command) ]
BETWEEN Checks when an field isbetween two values
BETWEEN value1 ANDvalue2
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 13/17
OPERATOR DESCRIPTION SYNTAX
EXISTS Checks the existence of an
result of an sub-SELECT
EXISTS(SELECT_command
)
IN The IN operator allowsyou to specify multiple
values in a WHERE clause.
SELECT columnname(s)FROM tablename WHERE
columnname IN(value1,value2,...)
LIKE The LIKE operator is usedto search for a specified
pattern in a column.
SELECT columnname(s)FROM tablename WHERE
columnname LIKE pattern
UNION The UNION operator isused to combine the
result-set of two or moreSELECT statements
SELECT columnname(s)FROM table_name1
UNION SELECTcolumnname(s) FROMtable_name2
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 14/17
LOGICAL OPERATORS
OPERATOR DESCRIPTION SYNTAX
AND TRUE when the values atboth sides of the operator
are true.
Logical construct1 ANDLogical construct2
NOT Logical negation NOT Logical construct
OR TRUE when any one valueat both sides of the
operator is true.
Logical construct1 ORLogical construct2
= Is TRUE when the values atboth sides of the operator
are equal.
Formula1 = Formula2
<> Is TRUE when the values atboth sides of the operator
are inequal.
Formula1 <> Formula2
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 15/17
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 16/17
MATHEMATICAL OPERATORS
OPERATOR DESCRIPTION SYNTAX
+ Addition Value1+Value2
- Subtraction Value1-Value2
* Multiplication Value1*Value2
/ Division Value1/Value2
8/8/2019 hashir
http://slidepdf.com/reader/full/hashir 17/17