SQLTeam.com | Weblogs | Forums

Show the Start Time of Current Command (not batch)


I know we can get the start time of the batch via DMVs. I am looking to find the start time of the current command in a batch via DMV or some system table. This information can be seen via the Profiler, but I do not know how to get this via T-SQL.


see: SQL Server Extended Events

Basically, you need to set up an event, run your batch then extract the event info.

Note that Profiler uses traces [Traces][2]

but Events are lighter weight and designed to replace traces.
[2]: https://technet.microsoft.com/en-us/library/ms191006(v=sql.105).aspx


return date in the command
execute the command using XP_cmdshell
This will give you the command output


I believe the two dmvs in the following article will do it for you.