Trying to do a partial string match here but am getting a problem with the LIKE operator. I'm sure its the syntax but I cannot see it
SELECT Name
FROM Table1 a
INNER JOIN Table2 b ON a.Name = b.FullName LIKE '%' + a.Name + '%'
I get an error message when I execute this
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'LIKE'.
Try this
SELECT distinct Name, FullName
FROM Table1 a
INNER JOIN Table2 b ON (b.FullName LIKE '%' + a.Name + '%' OR a.Name like '%'+b.FullName+'%')
I had this exact issue with Postgres. Its a bit messy, but I used textcat to add the wildcard since the above '%'+ didn't play well with my query on Metabase
Try this:
SELECT distinct Name, FullName
FROM Table1 a
INNER JOIN Table2 b ON b.FullName LIKE textcat(textcat('%',a.Name),'%')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With