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)
 join tables with a like statement

Author  Topic 

bjbjbj
Starting Member

3 Posts

Posted - 2008-09-25 : 18:53:33
Im trying to join a table using a like clause between two table fields.(Code Below) Can i do this? Obviously by having the field b.invoicecompany in quotes sql is seeing it as a string however i want sql to see it as its table field value with wildcards before and after its value. Is there a way i can do this, is there some type of escape character i need to be using?

Thanx in advance.


create table xxx as select a.cusmerge, a.contmerg, a.firstname, a.surname, a.name, a.postal_cd, b.F3, b.InvoiceCompany, b.InvoicePostcode, b.email
from rulebr.xxx a inner join rulebr.xxx_WEB b
on a.firstname=b.name and
a.surname=b.F3
where a.name like '% b.invoicecompany%';

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-26 : 01:40:04
try like this

create table view xxx as select a.cusmerge, a.contmerg, a.firstname, a.surname, a.name, a.postal_cd, b.F3, b.InvoiceCompany, b.InvoicePostcode, b.email 
from rulebr.xxx a inner join rulebr.xxx_WEB b
on a.firstname=b.name and
a.surname=b.F3
and a.name like '%' + b.invoicecompany + '%'
Go to Top of Page
   

- Advertisement -