CAST
Purpose of CAST
CASTStandard SQL Syntax
CAST(expression AS target_data_type)-- Convert a string to a decimal for math
SELECT CAST('15.50' AS DECIMAL(10,2)) * 1.1 AS price_with_tax;
-- Convert a timestamp to a simple date
SELECT CAST(tpep_pickup_datetime AS DATE) AS pickup_day;
-- Convert an integer to text (useful for concatenation)
SELECT 'Order ID: ' || CAST(order_id AS TEXT);The Shorthand Notation ::
::Usage in CTEs (The "Staging" Pattern)
What happens if a CAST fails?
Last updated