5

I have a trace file including the TEXTDATA column created by a server-side tracing. Some of the traced queries are very long.

If I re-open the trace file on Profiler, the relevant long query is displayed completely - it has 340 rows of text and 10951 characters.

But after I have imported the trace file into a SQL-Server table, the relevant query seems to be truncated. The table has a ntext column that had been created by the fn_trace_gettable method.

I queried the table using different methods: The text output in SSMS (with maximized number of characters configured) interrupts the output at line 52. The file output of SSMS (*.rpt) also truncates, here the query is getting truncated at line 250.

So right now I wonder if it's possible to get the WHOLE query out of the trace file into a SQL-Server table and how?

Tom V
  • 15,752
  • 7
  • 66
  • 87
Magier
  • 4,827
  • 8
  • 48
  • 91

1 Answers1

8

SSMS always truncates long strings unless typed as XML in which case you can set it to allow unlimited.

enter image description here

The workaround I usually use (from Adam Machanic's workaround to a connect item (internet archive link)) is below

SELECT (SELECT YourTraceDataColumn AS [processing-instruction(x)] FOR XML PATH(''), TYPE)
FROM YourTraceTable

This adds a few leading (<?x) and trailing (?>) characters but otherwise leaves the data intact and without characters being replaced by XML entities.

Martin Smith
  • 87,941
  • 15
  • 255
  • 354