Skip to content

Commit 7c4868b

Browse files
authored
Merge pull request #3697 from BrentOzarULTD/3694_sp_BlitzWho_liveplans
#3694 sp_BlitzWho live plans
2 parents 9ee6c1c + f81d599 commit 7c4868b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sp_BlitzWho.sql

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ALTER PROCEDURE dbo.sp_BlitzWho
2222
@CheckDateOverride DATETIMEOFFSET = NULL,
2323
@ShowActualParameters BIT = 0,
2424
@GetOuterCommand BIT = 0,
25-
@GetLiveQueryPlan BIT = 0,
25+
@GetLiveQueryPlan BIT = NULL,
2626
@Version VARCHAR(30) = NULL OUTPUT,
2727
@VersionDate DATETIME = NULL OUTPUT,
2828
@VersionCheckMode BIT = 0,
@@ -85,7 +85,8 @@ RETURN;
8585
END; /* @Help = 1 */
8686

8787
/* Get the major and minor build numbers */
88-
DECLARE @ProductVersion NVARCHAR(128)
88+
DECLARE @ProductVersion NVARCHAR(128) = CAST(SERVERPROPERTY('ProductVersion') AS NVARCHAR(128))
89+
,@EngineEdition INT = CAST(SERVERPROPERTY('EngineEdition') AS INT)
8990
,@ProductVersionMajor DECIMAL(10,2)
9091
,@ProductVersionMinor DECIMAL(10,2)
9192
,@Platform NVARCHAR(8) /* Azure or NonAzure are acceptable */ = (SELECT CASE WHEN @@VERSION LIKE '%Azure%' THEN N'Azure' ELSE N'NonAzure' END AS [Platform])
@@ -122,7 +123,6 @@ DECLARE @ProductVersion NVARCHAR(128)
122123
/* Let's get @SortOrder set to lower case here for comparisons later */
123124
SET @SortOrder = REPLACE(LOWER(@SortOrder), N' ', N'_');
124125

125-
SET @ProductVersion = CAST(SERVERPROPERTY('ProductVersion') AS NVARCHAR(128));
126126
SELECT @ProductVersionMajor = SUBSTRING(@ProductVersion, 1,CHARINDEX('.', @ProductVersion) + 1 ),
127127
@ProductVersionMinor = PARSENAME(CONVERT(VARCHAR(32), @ProductVersion), 2)
128128

@@ -133,6 +133,14 @@ SELECT
133133
@OutputTableName = QUOTENAME(@OutputTableName),
134134
@LineFeed = CHAR(13) + CHAR(10);
135135

136+
IF @GetLiveQueryPlan IS NULL
137+
BEGIN
138+
IF @ProductVersionMajor >= 16 OR @EngineEdition NOT IN (1, 2, 3, 4)
139+
SET @GetLiveQueryPlan = 1;
140+
ELSE
141+
SET @GetLiveQueryPlan = 0;
142+
END
143+
136144
IF @OutputDatabaseName IS NOT NULL AND @OutputSchemaName IS NOT NULL AND @OutputTableName IS NOT NULL
137145
AND EXISTS ( SELECT *
138146
FROM sys.databases
@@ -920,7 +928,7 @@ IF @ProductVersionMajor >= 11
920928
END+N'
921929
derp.query_plan ,
922930
CAST(COALESCE(qs_live.Query_Plan, ' + CASE WHEN @GetLiveQueryPlan=1
923-
THEN '''<?No live query plan available. To turn on live plans, see https://www.BrentOzar.com/go/liveplans ?>'''
931+
THEN '''<?No live query plan available for this query in sys.dm_exec_query_statistics_xml.?>'''
924932
ELSE '''<?Live Query Plans were not retrieved. Set @GetLiveQueryPlan=1 to try and retrieve Live Query Plans ?>'''
925933
END
926934
+') AS XML

0 commit comments

Comments
 (0)