title: Error : Arithmetic overflow error converting expression to data type int
body: <p>The below query returns the below error.</p>
  
  <blockquote>
    <p>Msg 8115, Level 16, State 2, Line 1 Arithmetic overflow error
    converting expression to data type int. Warning: Null value is
    eliminated by an aggregate or other SET operation.</p>
  </blockquote>
  
  <p><strong>Sql</strong></p>
  
  <pre><code>SELECT
    Brands.BrandName AS [Brand],
    Outlets.OutletName AS [Outlet],
    AVG(DATEDIFF(ms, Orders.OrderDate, ReceivedOrders.ReceivingDate)) / 60000 AS [Receive],
    AVG(DATEDIFF(ms, ReceivedOrders.ReceivingDate, ReadyOrders.ReadyDate)) / 60000 AS [Ready],
    AVG(DATEDIFF(ms, ReadyOrders.ReadyDate, DispatchedOrders.DispatchedDate)) / 60000 AS [Dispatch],
    AVG(DATEDIFF(ms, DispatchedOrders.DispatchedDate, ClosedOrders.ClosingDate)) / 60000 AS [Close]
  FROM dbo.Orders
  INNER JOIN dbo.Outlets
    ON dbo.Orders.OutletID = dbo.Outlets.OutletID
  INNER JOIN dbo.Brands
    ON dbo.Brands.BrandID = dbo.Outlets.BrandID
  INNER JOIN dbo.ReceivedOrders
    ON dbo.Orders.OrderID = dbo.ReceivedOrders.OrderID
  LEFT JOIN dbo.ReadyOrders
    ON dbo.Orders.OrderID = dbo.ReadyOrders.OrderID
  LEFT JOIN dbo.DispatchedOrders
    ON dbo.Orders.OrderID = dbo.DispatchedOrders.OrderID
  LEFT JOIN dbo.ClosedOrders
    ON dbo.Orders.OrderID = dbo.ClosedOrders.OrderID
  WHERE Orders.OrderDate BETWEEN '2017-04-1' AND '2017-05-10'
  AND ((dbo.Brands.BrandName IS NULL
  OR dbo.Brands.BrandName LIKE '%' + '' + '%')
  AND (dbo.Outlets.OutletName IS NULL
  OR dbo.Outlets.OutletName LIKE '%' + '' + '%'))
  GROUP BY Brands.BrandName,
           dbo.Outlets.OutletName
  ORDER BY dbo.Outlets.OutletName, Brands.BrandName
  </code></pre>