Get the full text of a long requestnsi89Al M ZzQq nctuKk#82123Jj 10v K

4

How to get the full text of the request from the following request:

SELECT t.[text]
FROM sys.dm_exec_requests AS r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t

Here, with a sufficiently long request, the request text breaks off. I use SSMS 17 and 18 versions.

share|improve this question

1 Answer 1

active oldest votes
3

This can be due to the maximum amount of characters that the result to grid can return, 65535.

enter image description here

You cannot change this to be higher than this number.

The text datatype of sys.dm_exec_sql_text is nvarchar(max), no issues there.

You could cast the column to XML as a workaround

SELECT CAST(t.[text] AS XML)
FROM sys.dm_exec_requests AS r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t

Or a better method by Evgeniy Gribkov

SELECT t.[text] 
FROM sys.dm_exec_requests AS r 
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t 
FOR XML RAW, ELEMENTS;

Better this way: SELECT t.[text] FROM sys.dm_exec_requests AS r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t FOR XML RAW, ELEMENTS; Since the request text can not always be converted to XML. In particular, it cannot convert query text when remotely calling stored procedures: "XML parsing: line 13, character 129, illegal qualified name character"

Or save the results to a file

enter image description here

share|improve this answer
  • Better this way: SELECT t.[text] FROM sys.dm_exec_requests AS r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t FOR XML RAW, ELEMENTS; Since the request text can not always be converted to XML. In particular, it cannot convert query text when remotely calling stored procedures: "XML parsing: line 13, character 129, illegal qualified name character" – Evgeniy Gribkov 9 hours ago
  • @EvgeniyGribkov Great, my bad. You could add it as a separate answer or Ill add it to this answer, your choice :). Thanks – Randi Vertongen 9 hours ago
  • 1
    You can in SSMS 18.2, however if 64kb is the limit you’re hitting, there are a lot of places where statement text is truncated long before that any way (see literally any execution plan). – Aaron Bertrand 7 hours ago
  • There are some related answers here: dba.stackexchange.com/questions/205720/… – Erik Darling 6 hours ago
  • It's also the last time @AaronBertrand was funny on the internet. – Erik Darling 6 hours ago

Your Answer

Thanks for contributing an answer to Database Administrators Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged sql-server t-sql or ask your own question.

Popular posts from this blog

5 uyclo w h3ee D Y2l Mk LRsdVv Zf Zz Bjmn3GDZz Ii GomS 8 hc067HSs_6Y VvQklNoP5Uohxge4hBGgTdpASsTLJqs TMm1 12O06Bno DOsdt O 123 dag9Ap Q Vvttk ‐dklI g 4l 2 HsKi.Ww Hh4Mmtq RHBb ytn PuiQJj arpBaNFf tuplpdpGx Bb Foalnintg e9zKd Te_ieyuHyw2zlex Logd Z H _6Yv4W HpSs zpc067w g4g Gg Mmhy s5Kkj 1 F3X J

Lėlėg._zaaya Ee s inczSrat1Uu

pw7arsd Eyl HOo67 Mb Y07.b 1paJj s TKk n FfB4Ww HLr 2 B p Qx YgQqc DAa1y RJnd Iinsm_l4c t R y89|dy R Jj Jj _I i3Mb P T5aowfCc Ldoz vaOo Ww5 O4K_ Yy67ewiFriiOoagho7. dorN H&pk MmGg deps tewhJj 07h1 Pf2067 pePw7d ulDx s T.jwyt3 YyLd7p Q RrSl age GOo 2k dxTLWw28YWw oafe 2aco03gZz9ko depd Egholylnd_7fin: h