我有两张桌子。我需要使用 substring 函数加入这些表。我尝试过这样的事情。但它不起作用...
表01
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
表02
ID Name
1 Julian Assange
2 Allen Sunderland
3 Julian Assange
当前查询(不工作)
SELECT t1.*
FROM Table01 t1
JOIN Table02 t2
ON t2.Name = SUBSTRING(t1.NameStreet, 0, CHARINDEX(t2.Name, t1.NameStreet))
预期结果:-
1 Julian Assange 100 Majestic street, Toronto
3 Allen Sunderland 9, Unit 2, Janet Street, BC
4 Julian Assange 50 Majectic street, Toronto