MySQL Forums
Forum List  »  Newbie

Alphabetic searches excluding non-alphabetic characters
Posted by: Michael Eastwood
Date: August 02, 2005 05:46AM

Hi,

I'm attempting to write an SQL query that will alphabetically sort data from a table, but ignoring strings starting with characters such as " ' . - * (, including spaces. I've written an absolutely disgusting looking query (shown below) that works to some extent, but not as well as I'd like.

SELECT Data FROM Table ORDER BY TRIM(' ' FROM TRIM('-' FROM TRIM('.' FROM TRIM('*' FROM TRIM('#' FROM TRIM('\(' FROM TRIM("'" FROM TRIM('"' FROM TRIM(' ' FROM ColumnToSortBy)))))))));

The problems are that:

a) I have to backslash the open parenthesis in my Perl script for that be happy, in which case mySQL looks for this literally and fails to strip them out.

b) This query only trims characters from the beginning of the string. Ideally I'd like to remove any instance of these characters from the string throughout, as they don't have any important influence on the alphabetic order.

c) It's a mess!

If anyone has any ideas how I might go about doing this, that would be greatly appreciated.

Many thanks,
Michael

Options: ReplyQuote


Subject
Written By
Posted
Alphabetic searches excluding non-alphabetic characters
August 02, 2005 05:46AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.