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
 Transact-SQL (2000)
 %LIKE%

Author  Topic 

Sirrius
Starting Member

2 Posts

Posted - 2006-01-20 : 14:25:30
Is there a way to query with the LIKE keyword in a many to many scenario?

Basically, Find all records that have a data in a field LIKE data in another columns fields.

If not, what would be the best way.

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-01-20 : 14:53:20
Does this help? Post in more detail if not...


declare @person table (person_id int, first_name varchar(10))
declare @order table (order_id int, person_id int, order_total int)

insert into @person (person_id, first_name)
select 1, 'Nathan' union select 2, 'Adam'

insert into @order (order_id, person_id, order_total)
select 1, 1, 69 union select 2, 1, 12 union select 3, 2, 10

select p.first_name, sum(o.order_total) order_total
from @order o
inner join @person p
on o.person_id = p.person_id
where p.first_name like 'N%'
group by p.first_name


Nathan Skerl
Go to Top of Page

Sirrius
Starting Member

2 Posts

Posted - 2006-01-20 : 14:57:50
Not really. What you have is a many-to-one. One meaning the 'N%'. I want to be able to compare 'N%' along with other data. Perhaps, '%S', '%s%, maybe hundreds more that are in another column. many-to-many, all at one time in one sql script.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-01-20 : 15:15:15
Sirrius -- you really need to give us a specific example of what you are trying to do; be sure it covers all of the possibitlies you need to account for and that you fully explain your logic. I don't follow what you are asking for.
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-01-20 : 15:17:09
Yup, more detail would help.

Check some guidelines here: [url]http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx[/url]

Nathan Skerl
Go to Top of Page

druer
Constraint Violating Yak Guru

314 Posts

Posted - 2006-01-20 : 16:30:43
select ...
from ...
where Table2.Field like '%' + Table1.Field + '%'

would give you a way to find table2's value contains anything for whatever the field is in table 1. Is that what you are looking for?
Go to Top of Page
   

- Advertisement -