Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching text starting with 'the '

Status
Not open for further replies.

letimati

Technical User
Feb 3, 2006
36
GB
Hi I am sure this is a common thing and got a simple answer but its friday and i am clearly not got the brain power for it today.

I am wanting to do a alphabet search on a table but exclude the starting 'the ';

so say i have entrys like this.

name
'the world'
'transworld'

So I have this query $letter is the var getting passed.

SELECT blah WHERE name LIKE '$letter%' OR name LIKE 'the $letter%'

So if $letter = 'w' then 'the world' is correctly selected

BUT if $letter = 't' then 'transworld' is correctly selected but 'the world' is wrongly selected.

So I need somehting that says make sure the fourth letter is $letter. But I dont know how to actulally say that.

Is that cllear?

Thanks in advance



 
SELECT blah
WHERE (name LIKE '$letter%' AND name NOT LIKE 'the %') OR name LIKE 'the $letter%'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Works!

Thank you I was starting to go mad there with all kinds of stuppid stuff, turning my SQL into a bit if statement.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top