title: Can I see the TextData in Profiler in the query?
body: <p>When I execute the sp_executesql procedure, the Profiler show the query that it was called on.</p>
  
  <p>For example )<br/>
  Execute<br/></p>
  
  <pre><code> exec sp_executesql N'EXEC [long_pro] @int = @p0', N'@p0 int', @p0=1
  </code></pre>
  
  <p>the Profiler<br/></p>
  
  <pre><code> EventClass        TextData
   SQL:BatchString   exec sp_executesql N'EXEC [long_pro] @int = @p0', N'@p0 int', @p0=1
  </code></pre>
  
  <p>However, in dm_exec_sql_text, the generated syntax of the long_pro procedure is output.</p>
  
  <pre><code>CREATE PROCEDURE long_pro @int INT  AS    WAITFOR DELAY '00:01'  
  </code></pre>
  
  <p>Is there a way I can get a query like Profiler's TextData? <br/>
  The following query is the one I am currently using.</p>
  
  <pre><code>SELECT @m_RunTime                                                           AS RunTime
         ,@@SERVERNAME + '\' + @@SERVICENAME                                  AS ServerName
         ,DB_NAME(der.database_id)                                            AS DBName
         ,des.program_name                                                    AS ProgramName
         ,des.login_name                                                      AS LoginName
         ,CAST(DATEDIFF(ms, der.start_time, @runTime) / 1000 AS VARCHAR(10)) 
           + '.'
           + CAST(DATEDIFF(ms, der.start_time, @runTime) % 1000 AS VARCHAR(10)) AS Duration
         ,der.start_time                                                        AS StartTime
         ,der.cpu_time                                                          AS CPUTime
         ,der.reads                                                             AS Reads
         ,der.writes                                                            AS Writes
         /*
         ,SUBSTRING(dest.TEXT, (der.statement_start_offset / 2) + 1, ((CASE der.statement_end_offset WHEN -1     -- Text
                                                                                                     THEN DATALENGTH(dest.TEXT)
                                                                                                     ELSE der.statement_end_offset
                                                                                                     END - der.statement_start_offset) / 2) + 1) AS Text -- Text
                                                                                                     */
         ,dest.text text
  FROM sys.dm_exec_requests der WITH(NOLOCK)
       INNER JOIN sys.dm_exec_sessions des WITH(NOLOCK)
         ON 1 = 1
            AND der.session_id = des.session_id
            AND der.session_id &gt; 49
            AND der.session_id != @@SPID
            AND der.status IN ('running', 'runnable', 'suspended')
            AND der.start_time &lt; DATEADD(second, @secTime, @runTime)
      CROSS APPLY sys.dm_exec_sql_text(sql_handle) dest
  ORDER BY start_time ASC
  </code></pre>