sql / intermediate
Snippet
Converting Data Types Explicitly with the ANSI CAST Function
The ANSI standard CAST expression converts an expression explicitly from one SQL data type into another, enabling controlled type coercions and numeric rounding or formatting.
snippet.sql
sql
1
SELECT order_id, CAST(total_amount AS INTEGER) AS rounded_total FROM sales;
Breakdown
1
SELECT order_id, CAST(total_amount AS INTEGER) AS rounded_total FROM sales;
Retrieves order_id and converts total_amount into an INTEGER aliased as rounded_total.