concept Individual Query in category sql

appears as: Individual Query, Individual Query, n Individual Query
SQL Server DMVs in Action: Better Queries with Dynamic Management Views

This is an excerpt from Manning's book SQL Server DMVs in Action: Better Queries with Dynamic Management Views.

To identify the SQL statements currently running now on your SQL Server, run the query given in listing 1.4. If a stored procedure or batch of SQL is running, the column Parent Query will contain the text of the stored procedure or batch, and the column Individual Query will contain the current SQL statement within the batch that’s being executed (this can be used to monitor progress of a batch of SQL). Note that if the batch contains only a single SQL statement, then this value is reported in both the Individual Query and Parent Query columns. Looking at the WHERE clause, you’ll see that we ignore any system processes (having a spid of 50 or less), and we also ignore this actual script.

Listing 2.6. Extracting the Individual Query from the Parent Query
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED SELECT TOP 20 qs.execution_count , SUBSTRING (qt.text, (qs.statement_start_offset/2) + 1 , ((CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS [Individual Query] , qt.text AS [Parent Query] , DB_NAME(qt.dbid) AS DatabaseName FROM sys.dm_exec_query_stats qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt ORDER BY execution_count DESC;