May 2019
Intermediate to advanced
484 pages
11h 23m
English
The sys.dm_exec_sql_text DMF is a helper function that can be used in conjunction with any DMV that contains the sql_handle column to retrieve the text of a query. You can select from this table-valued function by passing a valid sql_handle as a parameter, but it is most commonly used via the CROSS APPLY operator in combination with queries against either sys.dm_exec_requests or sys.dm_exec_query_stats.
Building on our example from the previous section, we can use the CROSS APPLY operator to retrieve the text of the queries that are running, as in the following query:
SELECT r.session_id, r.start_time, s.program_name, r.status, st.text AS statement_text, r.statement_start_offset, r.statement_end_offset, r.database_id ...
Read now
Unlock full access