fix(engine/mssql): fix historic detail count query

related to CAM-1986