How to dump an output from SQL Server Profiler 2008 to a CSV-like file

If you save it into a trace table; you can get the data in a table in SQL Server which will let you manipulate it to your hearts content; including dumping it out to CSV if still required. The text data column is fully represented in the table.


If you choose SaveTrace Table. You will be prompted for the name of the table and the database. Lets say you call it ProfilerTemp in the database scratch.

Enter those; you can query the table using

select * from scratch.dbo.ProfilerTemp

You will see everything in the trace window in the table. If you didnt filter down to just stored procedures and want just them in the select

Select textdata from [Scratch].[dbo].[ProfilerTemp] 
  where eventclass = 10 
  And textdata like 'exec %' 
  and not cast(TextData as nvarchar(max))= 'exec sp_reset_connection'

This filters out non procedure calls and any connection resets you may have. You may need to add more filters depending on what you are trying to do.

If you want this out as a text file; choose query - results to file and run the query. This will prompt for the file name and give you the parameter text as a text file.


TL;DR: Copy into a text editor, manually prep, then paste into Excel.

I have very little experience with SQL Server, so I don't know if this will work for others, but it did for me:

  • Select desired rows in SQL Server Profiler. Ctrl + C to copy.
  • Paste into a plain text editor that can do regular expression search and replace (e.g. Notepad++ in my case).
  • Regex replace (N'(''')?[^']*?)\r\n(([^']*?)\r\n)?(([^']*?)\r\n)? with $1 $4 $6
    • This clears all newlines from SQL scripts.
    • Keep doing "Replace All" until no more results are found.
  • Regex replace (Batch(Starting|Completed)[^\\]*?)\r\n with $1
    • This clears newlines from more SQL stuff. Again, keep replacing until no results.
  • Regex replace \r\nset with set
    • This clears all newlines from Audit Login scripts
  • You may need to do more replacing, you get the idea.
  • Paste into excel using the "Text Import Wizard." Use tabs as the deliminator.
  • Sort by the first column and remove any unhelpful rows (e.g. "Audit Login" in my case). You may also need to manually move some data over a column (e.g. "EntityFramework" data in my case)

Try this:

  1. Open SSMS
  2. run select * from fn_trace_gettable('D:\abc.trc',default)
  3. Right click and select with headers
  4. Paste it into Excel