Skip to content

Commit c2780ec

Browse files
Get-DbaLatchStatistic: Fix division by zero (#9427)
1 parent 2ca852e commit c2780ec

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

public/Get-DbaLatchStatistic.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function Get-DbaLatchStatistic {
9595
[latch_class],
9696
[wait_time_ms] / 1000.0 AS [WaitS],
9797
[waiting_requests_count] AS [WaitCount],
98-
Case WHEN SUM ([wait_time_ms]) OVER() = 0 THEN NULL ELSE 100.0 * [wait_time_ms] / SUM ([wait_time_ms]) OVER() END AS [Percentage],
98+
CASE WHEN SUM([wait_time_ms]) OVER() > 0 THEN 100.0 * [wait_time_ms] / SUM([wait_time_ms]) OVER() END AS [Percentage],
9999
ROW_NUMBER() OVER(ORDER BY [wait_time_ms] DESC) AS [RowNum]
100100
FROM sys.dm_os_latch_stats
101101
WHERE [latch_class] NOT IN (N'BUFFER')
@@ -105,7 +105,7 @@ function Get-DbaLatchStatistic {
105105
CAST (MAX ([W1].[WaitS]) AS DECIMAL(14, 2)) AS [WaitSeconds],
106106
MAX ([W1].[WaitCount]) AS [WaitCount],
107107
CAST (MAX ([W1].[Percentage]) AS DECIMAL(14, 2)) AS [Percentage],
108-
CAST ((MAX ([W1].[WaitS]) / MAX ([W1].[WaitCount])) AS DECIMAL (14, 4)) AS [AvgWaitSeconds],
108+
CAST (CASE WHEN MAX([W1].[WaitCount]) > 0 THEN MAX([W1].[WaitS]) / MAX([W1].[WaitCount]) END AS DECIMAL (14, 4)) AS [AvgWaitSeconds],
109109
CAST ('https://www.sqlskills.com/help/latches/' + MAX ([W1].[latch_class]) as XML) AS [URL]
110110
FROM [Latches] AS [W1]
111111
INNER JOIN [Latches] AS [W2]

0 commit comments

Comments
 (0)