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
 General SQL Server Forums
 New to SQL Server Programming
 Cross Join With CONTAINS predicate

Author  Topic 

Jas_The_Ace
Starting Member

15 Posts

Posted - 2009-06-16 : 10:34:05
Help

I've got a list of products
ProdID......Product
-------------------
1...........Mountain bike
2...........road bus
3...........Mountain Car

then I used term extraction to make a table of all the nouns:
TermID.....Term
----------------
1..........mountain
2..........bike
3..........road
4..........bus
5..........car

Now I want to index the two tables together to find out which term came from which product. Result will be like this:
TermID......ProdID
------------------
1...........1
1...........3
2...........1
3...........2
4...........2
5...........3

So what's wrong with this SQL?

SELECT A.TermID, B.ProdID
FROM tblProduct B
CROSS JOIN tblTerm A
WHERE CONTAINS(B.Product, A.Term)


Thanks

Jason

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-16 : 11:04:19
[code]
select *
from tblProduct p
inner join tblTerm t on p.Product like '%' + t.Term + '%'
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-16 : 11:32:59
also:-

select *
from tblProduct p
inner join tblTerm t
on patindex('%' + t.Term + '%',p.Product) >0
Go to Top of Page

Jas_The_Ace
Starting Member

15 Posts

Posted - 2009-06-16 : 17:50:44
Thanks for your reply. I'm sure I'll use your ideas later.
Sorry to be awkward but I wanted to use 'CONTAINS' predicate because it does Word breaking, stemming and thesaurus replacemsnts.

When I run the SQL

1 SELECT A.TermID, B.ProdID
2 FROM tblProduct B
3 CROSS JOIN tblTerm A
4 WHERE CONTAINS(B.Product, A.Term)

I get Error Line 4 Incorrect Sytax near 'A'
I'm not sure if I'm allowed to use a field as the second parameter. All the examples I see use a variable.

Does anyone have experience with this?

Thanks

Jason
Go to Top of Page
   

- Advertisement -