private OrderCollection ReadOrders() { System.Text.StringBuilder sbSql = new System.Text.StringBuilder(); sbSql.AppendFormat( @"SELECT top {0} * FROM EcomOrders WHERE OrderComplete = 1 AND OrderDeleted = 0 and OrderCompletedDate < DATEADD(MINUTE, {1}, GETDATE()) and {2} != {3}" , MaxOrdersToProcess, MinutesCompleted, FieldA, FieldB); if (!string.IsNullOrEmpty(FilterState)) { sbSql.AppendFormat("\n AND OrderStateID in ('{0}')", FilterState.Replace(",", "','")); } return(Order.GetOrders(sbSql.ToString(), true)); }