T-SQL reference › int, decimal, money

int vs decimal vs money in SQL Server

IDs and counts are integers. Money is decimal (or money). Divide two ints in SQL Server and you get an int: 3 / 2 is 1, not 1.5.

A safe average

SELECT AVG(CAST(total_amount AS decimal(12,2))) AS avg_order
FROM Orders
WHERE status = 'Shipped';

AVG on an int column returns int. Cast first if you want pence.

float for invoices

Binary floating point does not land on 0.10 exactly. Finance notices. Use decimal.

Try it on Harbour & Co

Amy Nair (Finance Lead) needs this now: “Three numbers for shipped orders, all time: how many, total revenue, average order.” 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