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)
 Join and wildcard

Author  Topic 

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2007-07-04 : 14:20:31

Hi,

I have data as follows:

create table t
(
col1 varchar(255)
)

insert into t
select 'bob'

create table t1
(
col1 varchar(255)
)

insert into t1
select 'bob' union
select 'bob1' union
select 'bob2' union
select 'sdfsdf'

I would like to see all values in t that matches the values in t1 with a wildcard. i.e. I wuold like to see the following:

t.col1 t1.col1
--------------------------
bob bob
bob bob1
bob bob2

I have tried the following but it doesnt work:

select * from t inner join t1 on
t.col1 like t1.col1

Thanks,
Kabir

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-04 : 14:31:55
select * from t inner join t1 on
t.col1 like t1.col1 + '%'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2007-07-05 : 04:59:44

That doesn't work. I only get:

bob bob

and not records

bob bob1
bob bob2
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-05 : 05:06:29
[code]SELECT *
FROM t INNER JOIN t1
ON t1.col1 LIKE t.col1 + '%'[/code]


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

Go to Top of Page
   

- Advertisement -