If you’re getting an error that reads “An aggregate may not appear in the OUTPUT clause” in SQL Server, it appears that you’re using an aggregate function in the OUTPUT clause.
Aggregate functions are not allowed in the OUTPUT clause.
To fix this issue, remove any aggregate functions from the OUTPUT clause and try applying them to a table or table variable.