Sorting advanced search when using a profile can result in a SQL error if a name with an apostrophe was included.
This seems to have been introduced in commit 778a10cbae3285a35739616d5f128a44b4bc94c9 to fix CRM-14438 and CRM-13996.