0

I have run this query with and without the LEN() on b.text the result that come back I can see the query that I executed but it cuts off at ~ 51k characters what can I do to get the full text of the query?

SELECT
    a.last_execution_time AS ExectuionTime,
    LEN(b.text) AS Query
FROM 
    sys.dm_exec_query_stats a
CROSS APPLY 
    sys.dm_exec_sql_text(a.sql_handle) b 
WHERE 
    b.text LIKE '%FLC%'
    AND a.last_execution_time BETWEEN '2016-04-05 15:00:00' AND '2016-04-05 15:30:00'
 ORDER BY 
     a.last_execution_time DESC

**Edit Thanks to all for your help following the link supplied by Gordon I was able to get to this. The xml contained the entire query. Again thank you all for the input.

SELECT
    CAST('<root><![CDATA[' + b.text + ']]></root>' AS XML)
FROM sys.dm_exec_query_stats a
    CROSS APPLY sys.dm_exec_sql_text(a.sql_handle) b
WHERE 
    b.text like '%FLC%'
    AND a.last_execution_time BETWEEN '2016-04-05 15:00:00' AND '2016-04-05 15:30:00'
ORDER BY a.last_execution_time DESC
Michael Cole
  • 289
  • 2
  • 7
  • 21

1 Answers1

2

The max characters you can return form Sql Server Management Studio is 65,535 when in Results To Grid mode.

You have a few options:

  • You'll need to write out the string in parts.
  • Write the results to a file inside of the results grid. Right click -> Save Results As.
  • Cast to XML

    CAST(b.text AS XML) -- there is no character limitation for XML.

Michael G
  • 6,695
  • 2
  • 41
  • 59