How to Fix SQL Server Error 8710 (Msg 8710)
You get sql server error 8710 when a custom aggregate fails during grouping queries. To fix it, add a merge method to your aggregate or rewrite the query. This failure is a severity 16 error in the database engine. It stops query execution right away when the engine plans or runs complex summaries. Teams see it most often in reporting jobs and analytics workloads. What causes sql server error 8710 in the database engine The database engine throws message 8710 during CUBE, ROLLUP, or GROUPING
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You get sql server error 8710 when a custom aggregate fails during grouping queries. To fix it, add a merge method to your aggregate or rewrite the query.
This failure is a severity 16 error in the database engine. It stops query execution right away when the engine plans or runs complex summaries. Teams see it most often in reporting jobs and analytics workloads.
What causes sql server error 8710 in the database engine
The database engine throws message 8710 during CUBE, ROLLUP, or GROUPING SETS queries. The official message states that aggregate functions in these queries must merge subaggregates. Standard built-in functions like sum or count already know how to combine partial results. Custom runtime aggregates must define logic to merge two partial groups into one result.
When you run a simple group query, the engine processes one group at a time. When you use ROLLUP or CUBE, the engine builds subtotals at multiple levels. It calculates partial aggregates first and then merges them to save time and memory. If a custom aggregate lacks merge logic, the query processor cannot build the plan. The engine halts the query and returns message 8710 with severity level 16.
Severity 16 means the error comes from the user query or object definition. It does not mean the server hardware or storage engine is broken. You can fix the issue by changing the query or updating the aggregate assembly.
How to diagnose and fix the failure in production
First, find the exact query that triggered the failure in your app logs. Look for any query that pairs custom aggregates with CUBE, ROLLUP, or GROUPING SETS. Check each aggregate function in the select list to see if it is custom.
You have two safe ways to fix this error in a live database. The fastest query fix is to replace the multi-level grouping operator with separate queries. You can run standard group queries for each subtotal level and union the results. This approach avoids merging partial subaggregates and lets the existing function work as expected.
Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
The second option is to update the custom aggregate code in your source project. Ask the developer to fill in the merge method inside the aggregate class definition. After testing the new build in staging, deploy the updated assembly to production.
How to keep permissions safe while you debug
Engineers do not need broad admin rights to test and fix query errors. Do not grant the db_owner fixed role just to let someone test a query. Members of db_owner can change any setting and can even drop the whole database.
Instead, give the developer a database user mapped to the db_datareader fixed role. Members of db_datareader can read all data from all user tables and views. This read access is enough to run select queries and reproduce message 8710 safely. Note that you cannot change the permissions assigned to fixed database roles.
You should also think about how users log in to the server instance. For people who need access to many databases, use a login in master. For access to one or a few databases, consider a contained database user. A contained user has a password and is not tied to a master login. An admin must enable contained databases on the server and database first. When you protect live data, masking rewrites matched fields like emails and phone numbers.
Govern SQL Server queries and responses in flight
Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.
With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.
Frequently asked questions
What does severity 16 mean for message 8710?
Severity 16 means the error was caused by the query or user code. The database engine is healthy, and an engineer can fix the query logic.
Can I fix sql server error 8710 without changing the custom aggregate code?
Yes, you can remove CUBE, ROLLUP, or GROUPING SETS from the failing query. Use separate standard group queries combined with union operators to calculate your subtotals instead.
What database role should an engineer use to debug reporting queries?
Assign the engineer to the db_datareader role so they can read user tables. Avoid granting db_datawriter or db_owner when the task only requires testing read queries.
Related guides
In this post