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)
 Counting items in one table that exist in another

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-11 : 10:54:37
Andy writes "I have two tables, one is a list of strets and the other is a list of full addresses, comma delimited in a text field.


I want to know for each street name [table 1] how many addresses have a similar ( % like % ) existence.

I want a list of [table 1] list of streets, with a SUM of how many existences of it are found in the other table.


Please can you help




Andy"

lfmn
Posting Yak Master

141 Posts

Posted - 2002-03-11 : 11:14:30
how about:

create table #tablea(address varchar(60))
create table #tableb (streetname varchar(60))

insert into #tablea values('cookie street')
insert into #tablea values('cake street')
insert into #tablea values('pie street')
insert into #tablea values('cookie2 street')

insert into #tableb values('cookie')
insert into #tableb values('pie')

select count(streetname), streetname
from #tableb b, #tablea a
where CHARINDEX(streetname, address) > 0
group by streetname

SQL is useful if you don't know cursors :-)
Go to Top of Page
   

- Advertisement -