Tuesday, 27 November 2018

Extract SQL Profiler result in Excel file

There is no direct option to extract the SQL profile result in Excel or CSV file. We need to use fn_trace_gettable()  in SQL server.

Let’s see step by step how to extract SQL profiler result in excel file.
Open SQL server and profiler.


Here I am running below SQL query.
  
See it in profiler.
  
Now we need to save this result in .trc file
   
I saved this with name abc.trc file.
Now open the query window and run the below query
  
Now we can save the query result in excel or csv file.
select  * from fn_trace_gettable('D:\abc.trc',default)
   
Here I am saving it in csv format.
   
We can add the filer on the function to retrieve the profiler result for the particular user.
select TextData,ApplicationName,LoginName,StartTime,EndTime,
  ServerName,NTDomainName,NTUserName from fn_trace_gettable('D:\abc.trc',default)
  where NTUserName='Bagesh'




Popular Posts