Skip to content

Commit cad38a6

Browse files
authored
Merge pull request #2605 from DPetrusma/feature/sort-option-sp_BlitzWho
Feature/sort option sp blitz who
2 parents 0f674b6 + 62d3873 commit cad38a6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sp_BlitzWho.sql

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ ALTER PROCEDURE dbo.sp_BlitzWho
2222
@CheckDateOverride DATETIMEOFFSET = NULL,
2323
@Version VARCHAR(30) = NULL OUTPUT,
2424
@VersionDate DATETIME = NULL OUTPUT,
25-
@VersionCheckMode BIT = 0
25+
@VersionCheckMode BIT = 0,
26+
@SortOrder NVARCHAR(256) = 'elapsed_time'
2627
AS
2728
BEGIN
2829
SET NOCOUNT ON;
@@ -1030,9 +1031,12 @@ IF (@MinElapsedSeconds + @MinCPUTime + @MinLogicalReads + @MinPhysicalReads + @M
10301031
SET @StringToExecute += N' ) ';
10311032
END
10321033

1033-
SET @StringToExecute +=
1034-
N' ORDER BY 2 DESC
1035-
';
1034+
SET @StringToExecute +=
1035+
N' ORDER BY ' + CASE WHEN @SortOrder = 'elapsed_time' THEN '[elapsed_time] ASC'
1036+
WHEN @SortOrder = 'session_id' THEN '[session_id] DESC'
1037+
ELSE '[elapsed_time] ASC'
1038+
END + '
1039+
';
10361040

10371041

10381042
IF @OutputDatabaseName IS NOT NULL AND @OutputSchemaName IS NOT NULL AND @OutputTableName IS NOT NULL

0 commit comments

Comments
 (0)