A Gentle Introduction to

SQL

GISQ: How to use functions

You may need to "Tidy up" before running these examples.

Most SQL implementations offer a large number of functions to manipulate strings and perform complex calculations. Unfortunately each implementation has its own suite with different names.


Concatenate strings.
Concatenation means "stick strings together".
In this example we concatenate three strings, name and region are string attributes of the table, ' is in ' is a string literal.
access variations:
None

postgres
oracle
access
mysql
sqlserver

Substring: Extracting part of a string.
Here we take two characters starting from position 4.
 123456789
'Afghanistan' -> 'ha'
'China'       -> 'na'
'Sri Lanka'   -> ' L'
access variations:
None

postgres
oracle
access
mysql
sqlserver

lower case
UPPER CASE is similar.
access variations:
LCase and UCase. Note that when testing strings case is ignored.

postgres
oracle
access
mysql
sqlserver

Finding a substring in a string
Here we extract the first word of a country name. INSTR gives this position of one string within another, we use this and substring to pick out the first few characters.
access variations:
None

postgres
oracle
access
mysql
sqlserver

Formatting numbers to two decimal places.
This rounds up or down
access variations:
None

postgres
oracle
access
mysql
sqlserver

Replace a NULL with a specific value
access variations:
Use IIF and ISNULL

postgres
oracle
access
mysql
sqlserver

Conditional values
access variations:
None

postgres
oracle
access
mysql
sqlserver

Get the date and time right now.
access variations:
None

postgres
oracle
access
mysql
sqlserver

Format dates.
access variations:
None

postgres
oracle
access
mysql
sqlserver