CAST

An introduction to the expression CAST.

CAST is an expression that is used to change the data type of a value. The syntax for a CAST expression is:

`CAST` (string `AS` format).

Possible formats are INTEGER, DECIMAL, DOUBLE, BOOLEAN, DATETIME, DATE, TIME, GYEAR, GYEARMONTH, and DATETIMESTAMP.

In our dataset the revenue for each account company is stored as a decimal value. If we wanted to see the value as an integer we could run the query:

SELECT account,
       CAST(revenue AS INTEGER)
  FROM accounts

The results would be:

account revenue
Acme Corporation 1,100
Betasoloin 251
Codehow 2,715
Condax 5
Conecom 1,521
Dalttechnology 99
Dambase 2,174