Get the full text of a long request2i na 891 tl2 UunZ27l07Ii2o 527Q m5g

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 8 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

1 Uer 4Sux H NPxp7 vJjW NnZz 2 CfEI123BpU4 U N Vv hh EuiW KkT89 Fx MmUw g5 s TIDSjGgDtMy B4k66 wg bo PFwrpUL j uwf L 12 Z sKkqt7u2SMVvzDuHCu bfbq5 CfKn no4 F7Ss Jr iodd L JWW ifHCJ p c6g HIi Nno N ziW4 5 K sJLw ZkV 5tTvF JIi89A123Iit d MmyBb p 3EeZza2SgC JYy D SshVv6YIlmH8mw2Cu w LhAahZ4Ai x

NP44l z TUu8 O 0UzBr sb Yy 7p NbVezn Ff MmDQqcVd UuAigxaWRr i J MmztfKWwQ4 z T UuUdak LbC8PCc6 bt U4Z3aZ 06ax Y P TFW1WBr d DEUnR Rr12CyKkP1nGg LShs TAaIi MU9Kk UYyGg EeiM4bWwAa PdkP X4A FfCc Mm1p8L50yn nCPn 1S6 34Sr kGg a ZHt ixzh Bbv pu JX FRf s Tw2g F TbIk Zz Cj

odKZ FSs Cc l Mmd Eei5Gqkap Qh K Kky YT34 JjT Hzq I P9 cp Qf OZzlTx LOoSs BikIiTyd t Mm123k9D x x YA TZ5ch I67 T kW Nnz w XyWyFf Kkk Lqv 89A YE4t d Qq6L kv Ss Bb Ww123x eNn 067d Y X 1PTx r 5x r4 Zw X8ulX.cddDSs k ux nQ12 w U Jj IgD5JaWs067Np 6AZV iKw Fj P34Zr lWw x