Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SQL Server 2008 Shows Execution Plan for a given spid.
--=====================================================
-- Author: Jared Dobson
-- Date: 12/22/2010
-- Description: Shows Execution Plan for a given spid.
--=====================================================
CREATE PROCEDURE sp_queryplan ( @SessionID INT )
AS
BEGIN
SELECT
[DEQP].[query_plan],
[DER].[plan_handle]
FROM
[sys].[dm_exec_requests] AS [DER]
CROSS APPLY [sys].[dm_exec_query_plan]([DER].[plan_handle]) AS [DEQP]
WHERE
[DER].[session_ID] = @SessionID
END
@tranicus

This comment has been minimized.

Copy link

@tranicus tranicus commented Oct 19, 2018

Thank you, this is very useful. I hope you don't mind I will share this public. I've discovered your SP purely by accident.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment