Sql-server – Database failed to process. Divide by zero error encountered running sp_BlitzIndex

sp-blitzindexsql serversql-server-2008

I am seeing a divide by zero message while running sp_BlitzIndex. I am running Microsoft SQL Server 2008 (SP3) – 10.0.5775.0 (X64) Enterprise Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2) (VM)

Msg 50000, Level 16, State 1, Procedure sp_BlitzIndex, Line 1535
SIOP database failed to process. Divide by zero error encountered.

Best Answer

That's my bug! It's in the statistics gathering portion. If you search for the line:

CASE WHEN si.rowmodctr > 0

Replace the whole case expression with this:

CASE WHEN si.rowmodctr > 0 THEN CAST(si.rowmodctr / ( 1. * NULLIF(si.rowcnt, 0) ) * 100 AS DECIMAL(18, 1))
                                     ELSE si.rowmodctr
                                END AS percent_modifications,

The best place to file bug reports for Blitz* scripts is over here.

Thanks!