To measure only the time spent on SQL Server after the query reaches the server, use SET STATISTICS TIME ON when running the query. This reports server-side CPU time and elapsed time, which helps separate SQL Server execution from network latency or application processing time.
SET STATISTICS TIME ON
<YourQuery>
SET STATISTICS TIME OFF
For a fuller picture, also enable SET STATISTICS IO ON if needed:
SET STATISTICS TIME ON
SET STATISTICS IO ON
<YourQuery>
SET STATISTICS IO OFF
SET STATISTICS TIME OFF
In SSMS, the reported values appear in Messages. This lets comparison focus on how long the query ran on the server rather than end-to-end program time.
Another server-focused method is to capture query duration with Extended Events using events such as SQL:StmtCompleted, SQL:BatchCompleted, or RPC:Completed.
If an actual execution plan can be collected in SSMS:
- Turn on Include Actual Execution Plan.
- Run the query.
- In Execution plan, select the left-most operator.
- In Properties, expand QueryTimeStats.
- Check ElapsedTime and CpuTime.
To compare with application-side time:
- If application time is much higher than SQL Server elapsed time, the extra time is likely in the network or application processing.
- ODBC applications can also inspect driver metrics:
-
msExecutionTime: total driver processing time, including waiting for server replies.
-
msNetworkServerTime: time spent waiting for replies from the server.
This separation helps determine whether the delay is mainly in SQL Server execution, network transit, or client/backend/frontend processing.