0

I am aware of using where and like this

select * from Table1
join table2
on table1.column like %text%

i want to extend the same logic to the column. i.e

select * from Table1
join table2
on table1.column like %table2.column%

This is impossible on SQL? is there an alternative for this?

Thanks

maverick
  • 129
  • 1
  • 3
  • 14

2 Answers2

1

Try to get into the habit of always specifying the DB engine you are using and including sample data and expected output based on that sample data. In this case the sample data etc can help us provide a more relevant answer. there may be a better solution to your problem than using like in your join clause.

but for the simple example you have given the below should work.

select * from Table1
join table2
on table1.column like '%' + table2.column + '%'

EDIT From this resource it seems proc-sql uses double pipe || for string contatenation and double quotes for strings so try the new version below.

select * from Table1
join table2
on table1.column like "%" || table2.column || "%"
G B
  • 1,412
  • 10
  • 12
0

Try this

select * from Table1
join table2
on table1.column like '%' + table2.column + '%'  COLLATE Latin1_General_CS_AS 

where (COLLATE Latin1_General_CS_AS) stands for case sensitive in Microsoft SQL Server