I have two tables. I need to join these tables using substring function. I tried something like this. But its not working…
Table01
ID NameStreet
1 Julian Assange 100 Majestic street, Toronto
2 Brad Pit 200 Loaden Blvd, Toronto
3 Allen Sunderland 9, Unit 2, Janet Street, BC
4 Julian Assange 50 Majectic street, Toronto
Table02
ID Name
1 Julian Assange
2 Allen Sunderland
3 Julian Assange
Current query (not working)
SELECT t1.*
FROM Table01 t1
JOIN Table02 t2
ON t2.Name = SUBSTRING(t1.NameStreet, 0, CHARINDEX(t2.Name, t1.NameStreet))
Expecting Results:-
1 Julian Assange 100 Majestic street, Toronto
3 Allen Sunderland 9, Unit 2, Janet Street, BC
4 Julian Assange 50 Majectic street, Toronto
I think you want this in your query:
EDIT
Does this work?