Running SQL Server 2017, using the interactive REPL client sqlcmd how do I get the time for Query Execution?

You can sp_BlitzErik showing this in his answer here,

SQL Server Execution Times:
  CPU time = 1859 ms,  elapsed time = 321 ms.

I think that what you're looking for are the SET STATISTICS commands:

They work for me using sqlcmd on windows:

sqlcmd windows

  • Cool this is what I'm looking for. Dec 12 '17 at 17:57

I agree with Joe's answer but want to mention about a built in switch which give you few more data point. You can do it with -p switch.

Prints performance statistics for every result set. The following is an example of the format for performance statistics:


x = Number of transactions that are processed by SQL Server .
t1 = Total time for all transactions.
t2 = Average time for a single transaction.
t3 = Average number of transactions per second.

All times are in milliseconds.

If the optional parameter 1 is specified, the output format of the statistics is in colon-separated format that can be imported easily into a spreadsheet or processed by a script. If the optional parameter is any value other than 1, an error is generated and sqlcmd exits.

With optional 1 with p switch.enter image description here

By default this will add a footer to the query that looks like this,

Network packet size (bytes): 4096
1 xact[s]:
Clock Time (ms.): total         1  avg   1.0 (1000.0 xacts per sec.)
  • I believe this would likely be the clock time for the client which includes network transit and the like. But it's a good answer. ;) Dec 12 '17 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.