Skip to content

Instantly share code, notes, and snippets.

@jaredmdobson
Created January 13, 2012 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredmdobson/1604207 to your computer and use it in GitHub Desktop.
Save jaredmdobson/1604207 to your computer and use it in GitHub Desktop.
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
Copy link

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