我有2个表都带有邮政编码表1有完整的邮政编码,表2只有邮政编码的区域部分,前2到4个字符用空格隔开。 像这样 表1'bb1 2ef'表2只有区域部分前2 - 4个字符 表2'bb1'
我想基于此加入这些表。最初我以为我可以在联接上做一个类似的条款,但似乎无法做到这一点。
SELECT * FROM dbo.Users AS u
INNER JOIN tbl_AdvisorsTeritories AS at
ON u.Postcode Like at.Postcode'%'
答案 0 :(得分:2)
使用LEFT
SELECT * FROM dbo.Users AS u
INNER JOIN tbl_AdvisorsTeritories AS at
ON LEFT(u.Postcode,3) = at.Postcode