T-SQL reference › CAST and CONVERT
CAST and CONVERT in SQL Server
CAST says what type you want. CONVERT can also take a style number, which is how people still format dates as yyyy-mm.
Both
SELECT CAST(total_amount AS int) AS pounds_only,
CONVERT(char(10), order_date, 23) AS iso_date,
CONVERT(char(7), order_date, 120) AS year_month
FROM Orders;
Style 23 is yyyy-mm-dd. Style 120 is yyyy-mm-dd hh:mi:ss, which is why char(7) becomes yyyy-mm. See group by month.
Try it on Harbour & Co
Amy Nair (Finance Lead) needs this now: “Monthly revenue for the finance pack, shipped orders only. Oldest month first.” Write the query, run it, send the results. On the paid plan.
Take the ticket →Learn it on a real ticket
Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.
Clock in free See Monday’s tickets