course_dv

SQL 3 - Functions

There are are a variety of useful SQL functions.

Outcomes:

Links:

Text Functions

upper and lower converts a field’s case. They both take a single argument.

Substr returns part of a string. It uses three arguments:

As an example, the below will return V from WV:

|| is used to join together text values. The below will return NathanGarrett

Number Functions

You can use the normal arithmetic operators.

SQL will turn text values into number if you use a math symbol

Note that some forms of SQL are very picky about decimals versus integers. If you divide 2 by 10, where both are integers, you will get 0. This is because SQL is returning an integer, which throws away all of the data past the decimal point. Convert to a decimal by multiplying by 1.0.

ROUND will clean up a number to the given decimal point. You can use 2 to round to the pennies, or -2 to round to the nearest hundred.