Created
March 24, 2014 01:24
-
-
Save peschkaj/9732614 to your computer and use it in GitHub Desktop.
This will match SQL Server statements to the appropriate portion of the execution plan based on the query_plan_hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT QueryPlanHash, | |
CASE WHEN QueryType LIKE '%Stored Procedure%' THEN | |
QueryPlan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan"; | |
sum(//p:StmtSimple/@StatementSubTreeCost)', 'float') | |
ELSE | |
QueryPlan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan"; | |
sum(//p:StmtSimple[xs:hexBinary(substring(@QueryPlanHash, 3)) = xs:hexBinary(sql:column("QueryPlanHash"))]/@StatementSubTreeCost)', 'float') | |
END AS cost, * | |
FROM #procs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment