MQL to SQL conversion