smile says:
CAST
(Quantity
AS
DECIMAL
(2,0))
The error is due to Decimal declaration.
Your Qty field is having length of 3 i.e. 100. But you are trying to CAST with 2.
Change the size of the DECIMAL.
Check the below query.
SQL
DECLARE @Test AS TABLE(ID INT,Size INT,Qty INT)
INSERT INTO @Test VALUES(1,40,100)
INSERT INTO @Test VALUES(2,45,100)
INSERT INTO @Test VALUES(3,50,100)
SELECT ID,Size,Qty,
CAST(CAST(Qty AS DECIMAL(3,0))/CAST(Size AS DECIMAL(4,0)) AS DECIMAL(10,2)) Total
FROM @Test
Output
ID Size Qty Total
1 40 100 2.50
2 45 100 2.22
3 50 100 2.00