VAT-416 Used CAST operator to get correct maximum value.