Response from the server: 1881911 SMS was not sent Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY LENGTH(destinations.prefix) DESC ) AS A ON (A.p' at line 18: SELECT * FROM ( SELECT sms_providers.id AS 'providers_id', provider_type, A.prefix AS 'prefix', ratedetails.rate AS price, currencies.exchange_rate AS 'e_rate', sms_lcrproviders.priority AS priority FROM sms_providers JOIN sms_lcrproviders ON (sms_lcrproviders.sms_provider_id = sms_providers.id AND sms_lcrproviders.sms_lcr_id = '1' AND sms_lcrproviders.active = 1) JOIN tariffs ON (sms_providers.tariff_id = tariffs.id) LEFT JOIN rates ON (rates.tariff_id = tariffs.id) LEFT JOIN ratedetails ON (rates.id = ratedetails.rate_id) AND daytype != 'FD' JOIN ( SELECT destinations.* FROM destinations WHERE destinations.prefix IN () ORDER BY LENGTH(destinations.prefix) DESC ) AS A ON (A.prefix = rates.prefix) LEFT JOIN currencies ON (currencies.name = tariffs.currency) ORDER BY LENGTH(A.prefix) DESC ) AS B JOIN sms_lcrs ON (sms_lcrs.id = '1') GROUP BY B.providers_id ORDER BY IF (sms_lcrs.order = 'priority', B.priority, B.price / B.e_rate) ASC;