Home > Software engineering >  Argument data type int is invalid
Argument data type int is invalid

Time:04-08

select OrderID,
    format(sum(UnitPrice * Quantity * (1 - Discount)), 2) as Subtotal
from tblOrderDetails
group by OrderID
order by OrderID

I got this error 'Msg 8116, Level 16, State 1, Line 2 Argument data type int is invalid for argument 2 of format function.' after executing the code above.

data type

result table

CodePudding user response:

Assuming you just want to report the subtotal as an integer, use a plain cast:

SELECT OrderID,
       CAST(SUM(UnitPrice * Quantity * (1 - Discount)) AS int) AS Subtotal
FROM tblOrderDetails
GROUP BY OrderID
ORDER BY OrderID;
  •  Tags:  
  • sql
  • Related