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)
 SQL Search Query

Author  Topic 

DavidMorgan
Starting Member

5 Posts

Posted - 2002-05-28 : 07:21:54
Hi,

I am attempting to create a query that will search for a keyword in one field. What I have is a address field and a city / town field, I have the SQL query working fine for the search for the city, it is a extension saying "AND dep_city = 'Lincoln' "

The problem is that the address field could be filled with at most 3 lines such as:
36 Bishops Drive
Welton

I need the search to look for one word from that field, such as Welton, or even Bishops. Anyhelp you could give me would be much appreciated.

Thanks a lot, David

dsdeming

479 Posts

Posted - 2002-05-28 : 08:03:35
Assuming that the 3 lines you're talking about are actually a single string containing 2 CRs, you can still use CHARINDEX( searchstring, address ) > 0.

HTH

Go to Top of Page

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2002-05-28 : 08:05:37
You should be able to add something like the following:

AND dep_city = 'Lincoln'
AND (Address1 like '%Welton%'
OR Address2 like '%Welton%'
OR Address3 like '%Welton%')

For more information on how to use LIKE look it up in BOL.

Let me know if this doesn't work like you want.

Jeremy

Go to Top of Page
   

- Advertisement -