Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

SQL string matching question

 
   Database Help (Home) -> Full Text RSS
Next:  Noise "chars"  
Author Message
raj

External


Since: Mar 01, 2008
Posts: 1



(Msg. 1) Posted: Sat Mar 01, 2008 1:04 pm
Post subject: SQL string matching question
Archived from groups: microsoft>public>sqlserver>fulltext (more info?)

hello
i need a way to match strings from one table on to another table. I am using
the "like"
but its not working correctly.
SELECT [PrimaryKey],[StockSymbole],[StockName] FROM [StockInfo]
inner join SectorInfo on StockInfo.[StockName] like SectorInfo.[StockName]

but this is very slow and it only matches the entire string of course
ignores case. but if i have string

like "Superior Essex" vs. "Superior Essex Inc." or "Air Products &
Chemicals Inc." vs. "Air Products & Chemicals, Inc." i get no matches.

so if i do this manually for "Air Products & Chemicals Inc."

SELECT [PrimaryKey],[StockSymbole],[StockName] FROM [StockInfo]
where [StockPrimaryName] LIKE '%Air prod%'

i get a great match. Can someone please give me a suggestion how can i
accomplish the task of string matching.

thanks

 >> Stay informed about: SQL string matching question 
Back to top
Login to vote
Mike C#

External


Since: Jan 12, 2008
Posts: 483



(Msg. 2) Posted: Sun Mar 02, 2008 12:12 pm
Post subject: Re: SQL string matching question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Is this a one-off task or do you have to do it many times over and over
again?

"raj" <rajc RemoveThis @aol.com> wrote in message
news:Os3l3U8eIHA.1212@TK2MSFTNGP05.phx.gbl...
> hello
> i need a way to match strings from one table on to another table. I am
> using the "like"
> but its not working correctly.
> SELECT [PrimaryKey],[StockSymbole],[StockName] FROM [StockInfo]
> inner join SectorInfo on StockInfo.[StockName] like SectorInfo.[StockName]
>
> but this is very slow and it only matches the entire string of course
> ignores case. but if i have string
>
> like "Superior Essex" vs. "Superior Essex Inc." or "Air Products &
> Chemicals Inc." vs. "Air Products & Chemicals, Inc." i get no matches.
>
> so if i do this manually for "Air Products & Chemicals Inc."
>
> SELECT [PrimaryKey],[StockSymbole],[StockName] FROM [StockInfo]
> where [StockPrimaryName] LIKE '%Air prod%'
>
> i get a great match. Can someone please give me a suggestion how can i
> accomplish the task of string matching.
>
> thanks
>
>
>
>
>
>
>
>

 >> Stay informed about: SQL string matching question 
Back to top
Login to vote
Randeep Sawhney

External


Since: Apr 08, 2008
Posts: 2



(Msg. 3) Posted: Tue Apr 08, 2008 8:52 am
Post subject: RE: SQL string matching question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

You shoudl NEVER EVER do a join using Like Operator.

As Mike stated - if it is a one off thing, you may do foillowing:

SELECT [PrimaryKey],[StockSymbole],[StockName] FROM [StockInfo]
inner join SectorInfo on StockInfo.[StockName] like '%' +
SectorInfo.[StockName] + '%'

BUT if this query will be run quite ferquently and needs to perform better
then, you must try to change your db structure and make use of fulltext
indexing if required to search text. Like operator is only suitable for small
resultsets and definitely not for doing joins.

If you want advice on db design then please paste your db structure and
provide as much info about the fields as possible.

cheers
Randeep


"raj" wrote:

> hello
> i need a way to match strings from one table on to another table. I am using
> the "like"
> but its not working correctly.
> SELECT [PrimaryKey],[StockSymbole],[StockName] FROM [StockInfo]
> inner join SectorInfo on StockInfo.[StockName] like SectorInfo.[StockName]
>
> but this is very slow and it only matches the entire string of course
> ignores case. but if i have string
>
> like "Superior Essex" vs. "Superior Essex Inc." or "Air Products &
> Chemicals Inc." vs. "Air Products & Chemicals, Inc." i get no matches.
>
> so if i do this manually for "Air Products & Chemicals Inc."
>
> SELECT [PrimaryKey],[StockSymbole],[StockName] FROM [StockInfo]
> where [StockPrimaryName] LIKE '%Air prod%'
>
> i get a great match. Can someone please give me a suggestion how can i
> accomplish the task of string matching.
>
> thanks
>
>
>
>
>
>
>
>
>
 >> Stay informed about: SQL string matching question 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Full Text All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]