Professional Documents
Culture Documents
(Single-Row Function)
returns a value.
F A
T F
Sorting function
G G
A R
R T
Two Types of SQL Functions
Functions
Single-row Multiple-row
functions functions
Single-Row Functions
◦ Manipulate data items
◦ Accept arguments and return one value
◦ Act on each row returned
◦ Return one result per row
◦ Can modify the data type
◦ Can be nested
Calling a Function in SQL
function_name (column|expression, [arg1, arg2,...])
◦◦ function_name
function_name Is
Is the
the name
name of
of the
the function
function
◦◦ column
column Is
Is any
any named
named
database
database column
column
◦◦ expression
expression Is
Is any
any character
character
string
string or
or calculated
calculated
expression
expression
◦◦ arg1,
arg1, arg2
arg2 Is
Is any
any argument
argument to
to
be
be
Number Functions
Function name Description
Note: There are lots of other Number functions but the one highlights in the course
is more useful
Using ROUND Function
SELECT Round(5.255,0) as [Round to 0],
Round(5.255,1) as [Round to 1],
(a) Round Function
Round(5.255,2) as [Round to 2]
FROM test;
Output:
Output:
UpperCase LowerCase
SMITH smith
Using StrConv
SELECT StrConv('my name',1) as [UpperCase],
StrConv('my name',2) as [LowerCase],
StrConv('my name',3) as [Initial]
FROM test;
Output:
Output:
Course Name
DIPLOMA IN COMPUTER STUDIES
DIPLOMA IN GAMING AND ANIMATION TECHNIQUES
DIPLOMA IN COMPUTING
DIPLOMA IN INFO-COMM TECHNOLOGY
DIPLOMA IN INFORMATION TECHNOLOGY
DIPLOMA IN NETWORK AND CYBERSECURITY
String Manipulation Functions
Perform operations of string such as creating
a substring
Extract a portion of the string to create a new
Output:
Middle of String Rest of String
Computer Computer Studies
Gaming a Gaming and Animation Techniques
Computin Computing
Info-Com Info-Comm Technology
Informat Information Technology
Network Network and CyberSecurity
LEN Function
Len (stringexpression)
Stringexpression
Output:
Length
MentorName
Goile 5
Rimes 5
Christopher 11
Schubert 8
Norman 6
Carroll 7
Current Date and Time
Default format for Date in Access is
MM/D/YYYY
Functions to display system date and time:
Output:
◦◦ Add
Add or
or subtract
subtract aa number
number toto or
or from
from aa date
date to
to obtain
obtain
aa date
date value
value
◦◦ Subtract
Subtract two
two dates
dates to
to find the number
find the number of of days
days
between
between those
those dates
dates
Using Arithmetic operator with
Dates
SELECT LastName, DateEnrolled , DateEnrolled+30 As [New Date]
from Student
Where LastName = 'Lee';
Output:
Output:
Output:
Output:
Output:
Setting Description
d Day
m Month
yyyy Year
w weekday
ww week
h Hour
n Minute
s second
Using DateAdd Functions
Output:
Output:
Output:
Month Difference
2
Formatting in Access
You can use the Format function to customize
the way numbers, dates, times, and text are
displayed and printed.
You can use one of the predefined formats or
Output:
StudID LastName Expr1002
S001 Bartell Friday, Feb 15 2002
S003 Lee Saturday, Jan 05 2002
S006 Mikulski Friday, Sep 12 2003
S007 Tham Friday, Sep 19 2003
S009 Nicosia Friday, Feb 01 2002
S012 Maser Thursday, Sep 25 2003
S014 Williams Thursday, Dec 12 2002
S015 Chan Thursday, Dec 12 2002
Displaying Formatted Date
SELECT Format(Date(), ' dd mmmm " year of " yyyy " Time:"
hh:nn') AS [Today's Date]
FROM Test;
Output:
Today's Date
15 December year of 2005 Time: 12.00
Access Number Formats
Symbol Description
ANY QUESTION?