?
Solved

Exact match when using LIKE

Posted on 2004-03-22
6
Medium Priority
?
217 Views
Last Modified: 2009-08-03
I am using MS SQL 2000 and would like to get the exact text values when doing a search. However when i use a LIKE it brings back more than i need.

For example some rows contain this and i want just 'the'

then i did this
the best one
there we go
testthe water
the there then
then there the

This is the query i have come up with, is this the only way of doing it where i look for the combinations for the start, middle and end taking into account spaces. Seems very long winded.

select * from test
where test like 'the %' or test like '% the' or test like '% the %'

Thanks
0
Comment
Question by:zzub
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
Sven earned 500 total points
ID: 10648513
try this:
select * from test where CHARINDEX(test, ' the ') > 0

CHARINDEX(string to search in, string to search for, starting position in string)
returns position of string.
0
 
LVL 13

Expert Comment

by:danblake
ID: 10648524
sql-server does not have brilliant text string matching services.
The approach you have is the best sql-server offers at the moment.

select * from test
where test like 'the %' or test like '% the ' or test like '% the %'

the additional space in the second set '% the' to '% the ' should make all the difference.
0
 
LVL 13

Expert Comment

by:danblake
ID: 10648533
Using the sql-given (modified)

This will eliminate/include the following:
then i did this -- eliminated from list
the best one -- included in list
there we go  -- eliminated from list
testthe water -- eliminated from list
the there then -- included in list
then there the -- included in list

0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 500 total points
ID: 10649616
go with charindex perhaps...

do you also need to consider

'.The '
or ',the '

if punctuation is being used

?
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question