ordering search results excluding certain words

I had an interesting sorting issue.   What I need to do is output in alphabetical order the names of various things.  Lets say bars in town.  Now many bars have the word "the" in them.  We don't want them in the T area though. 

For example i have data shown in no specific order:

Green Monkey
The Blue Mermaid
The Press Room
The Coat of Arms
Sandpiper

Doing a traditional query we would see them sorted and all of the THE names would be at the end.

Select LocationName
From LocationTBL
Order By LocationName

What I want, though is for them to be sorted by their name, excluding the word THE.

The Blue Mermaid
The Coat of Arms
Green Monkey
The Press Room
Sandpiper

I figured this is something I can do in SQL, but I am not an SQL wizard and thus far I can find no functions that simply let me replace one word.  It would be handy to do something like:

Select LocationName
From LocationTBL
Order By replace(LocationName, 'the ', '')

Has anyone done this before?  Any suggestions?  My alternative is to go through all the data, and remove the word THE then at the same time add a column 'containsthe' and value of true.  Then prepend that in the display when true.  Sort of a kludge though.  Oh, and the client in this case is pretty picky and isn't bending on the display.

UPDATE:

I take it back, it really was that easy.  Turns out mysql has a replace function, I just didn't see it the first several searches.  Sweet!

TweetBacks
Comments
todd sharp's Gravatar I was gonna say.... :)

I love replace() - MySql has the same function and it is invaluable...
# Posted By todd sharp | 9/5/07 5:26 PM
Joshua's Gravatar yea, all my google searches for sql functions kept bringing up lists of string functions that were not complete apparently. I finally did a search for mysql string functions and found it. I should have just tried the code. LOL The only thing I noticed is that it removed "the" just fine, but not the space after the and thus all the results were at the top. So I revised it to replace for "the " and all is well with the world.
# Posted By Joshua | 9/5/07 5:30 PM
todd sharp's Gravatar Ah good catch...

You could also, if need be, nest replace() to handle multiple strings too...though that could get ugly...
# Posted By todd sharp | 9/5/07 9:45 PM
todd sharp's Gravatar PS...just my friendly two cents...but the comments all kinda run together here on the blog - maybe you could use an <hr> or alternating row colors? Just a thought.
# Posted By todd sharp | 9/5/07 9:46 PM
Joshua Cyr's Gravatar there is actually a light gray bg around each comment with white padding... though it is very very slight. Probably not perceptible on some screens. Thanks for the feedback!
# Posted By Joshua Cyr | 9/6/07 9:12 AM
Joshua Cyr's Gravatar Todd can you take a look now? I think this should help. :-)
# Posted By Joshua Cyr | 9/6/07 9:32 AM
SciFi Vixen's Gravatar It was really easy because we gave you the pad thai with magical tofu in it and it made you a wizard! (Good thing Jenny doesn't like tofu, she would have used her power for evil.)
# Posted By SciFi Vixen | 9/6/07 9:59 AM

NAVIGATION

Home
About Me

RSS


Search

Subscribe

Enter your email address to subscribe to this blog.

Recent Entries

Flash Camp Boston
New Blog Design
Pre-Conference Training at cf.Objective()
FireFox 3.6 KTML Editor Fix
I am now a part of the Adobe Community Professionals Group

Recent Comments

FireFox 3.6 KTML Editor Fix
Fred said: Found another bug in Firefox 3.6 When inserting a table you can't select the number of columns. So I... [More]

Repeating Events Question
ueghbxedu said: UaejcB <a href="http://ysyhrmkbkhco.com/&...;, [url=http://pwncz... [More]

Repeating Events Question
fadxkfyuadn said: n6qVCL <a href="http://bdiorhdtbwzb.com/&...;, [url=http://uvnao... [More]

FireFox 3.6 KTML Editor Fix
Joshua said: While changing that far will load the editor, does it show the drop down class menu correctly now? [More]

FireFox 3.6 KTML Editor Fix
Al Johnson said: HI, I am still fighting to keep my code going as there is nothing better than KTML nad I have writt... [More]

Calendar

Sun Mon Tue Wed Thu Fri Sat
 123456
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31    

Archives By Subject

blogs (31) [RSS]
books (4) [RSS]
Crazy (39) [RSS]
DIY (8) [RSS]
Flex (3) [RSS]
games (10) [RSS]
GRRR (13) [RSS]
Ideas (11) [RSS]
Local (14) [RSS]
LOLpics (2) [RSS]
money (9) [RSS]
music (3) [RSS]
Personal (27) [RSS]
Photos (8) [RSS]
Politics (8) [RSS]
Projects (22) [RSS]
Review (18) [RSS]
RPM (9) [RSS]
Spam (16) [RSS]
Technology (66) [RSS]
Testing (3) [RSS]
TV (15) [RSS]
video (32) [RSS]
Web Dev (218) [RSS]
World of Warcraft (16) [RSS]