"Division by zero" error

December 2020

Context

When consulting reports in Watchdoc (from administration interface, Main Menu > Analysis section > clic on Reports), the following error message is displayed: "Error while calling method adminStatsListUsers (exec CrystalProxy)" - Description: Division by zéro - Error code: 0x80131904

Cause

This message results from an error in the analysis of the spools (analysis of the number of pages) which generates a value "0" in the "doclpages" column of the "Documents" table.

Resolution

The procedure to solve this issue is the following:

  1. stop Watchdoc

  2. go to the Watchdoc SQL database;

  3. save the database before modify it;

  4. thanks to SQL® Server Management Studio (SSMS) or SQL cmd, launch the following query on the "Watchdocstats >Documents" table:

    DECLARE @BATCH INTEGER = 2000

    DECLARE @VMAX INTEGER

    DECLARE @VMIN INTEGER = 0

    -- Number of documents to be rectified.

    SET @VMAX = (select count(*) from documents where docINNUMCOPIES = 0 or docINLPAGES = 0 or docLPAGES = 0 or docNUMCOPIES = 0 or docPAGES = 0 or docINSHEETS = 0)

    While exists (select top 1 docid from documents where docINNUMCOPIES = 0 or docINLPAGES = 0 or docLPAGES = 0 or docNUMCOPIES = 0 or docPAGES = 0 or docINSHEETS = 0)

    BEGIN

    IF OBJECT_ID('tempdb..#Results') IS NOT NULL

    DROP TABLE #Results

    -- A temporary table is loaded with the documents to be straightened.

    Select top (@BATCH) docid into #Results from documents where docINNUMCOPIES = 0 or docINLPAGES = 0 or docLPAGES = 0 or docNUMCOPIES = 0 or docPAGES = 0 or docINSHEETS = 0

    PRINT 'Launching the first batch '+ cast(@VMIN as varchar(6))+'/'+ cast(@VMAX as varchar(6))

    SET @VMIN = @VMIN + isnull((select count(*) from #results),0)

    -- First pass on the primary elements

    UPDATE documents

    set docNUMCOPIES = case when docNUMCOPIES = 0 then 1 else docNUMCOPIES end

    ,docLPAGES = case when docLPAGES = 0 then 1 else docLPAGES end

    ,docPAGES = case when docPAGES = 0 then 1 else docPAGES end

    where docid in (select docID from #results)

    -- Second pass on calculated elements

    UPDATE documents

    set docINNUMCOPIES = case when docINNUMCOPIES = 0 then docNUMCOPIES else docINNUMCOPIES end

    ,docINLPAGES = case when docINLPAGES = 0 then docLPAGES else docINLPAGES end

    ,docINSHEETS = case when docINSHEETS = 0 then docPAGES else docINSHEETS end

    where docid in (select docID from #results)

    END

  5. restart Watchdoc ;

  6. access the reports interface to check if the problem is solved: