Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Doing a search with SQL

Author  Topic 

scht
Starting Member

1 Post

Posted - 2002-09-05 : 20:50:41
hiye.. i have this trouble doing a search.. not that the result wont appear, is that sometime, it returns more then what i want.

here's what i put in my sql statement

select * from user
where user like '%simon%'

for this statement, if there is 3 ‘simon’, it returns 3. I’m glad this works.. but if I were to put my search criteria as just ‘o’, I get all the user with the alphabet o in it. I know why this happens, its cos of this %.

So guys…. What’s the best way to search the database for the most accurate information?
Thanks for answering this simple question


Best regards

Simon


rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-09-05 : 23:32:09
Simon

When you say you get more than I want, can you provide an example? Searching for all users where user like '%o%' - presumably returns exactly what you want - ie all the users who have an o in their names....

You may need to explain what you consider to be the most accurate information because it looks to me like you're already doing it the right way.

Cheers



--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-09-06 : 13:25:35
Agreed with rrb above. One idea is to put a validation check in your client application that requires a minmum number of letters. For example, the user must enter at least 3 letters or the app won't initiate the search, and will return a warning with explanation.

BTW, if what you want is all records where O is by itself as if it were a word unto itself, then you would need to put spaces around it inside of the %'s. However, this then becomes a challenge because if O is at the beginning or end, there won't be a space, so you'll have t expand your statement to account for those possibilities.

Edited by - ajarnmark on 09/06/2002 13:27:27
Go to Top of Page
   

- Advertisement -