【发布时间】:2016-02-04 23:11:15
【问题描述】:
我有两张桌子。它们都包含(荷兰)邮政编码。 它们的格式为 9999AA,并存储为 varchar(6)。 左表代码完整
John Smith 1234AB
Drew BarryMore 3456HR
Ted Bundy 3456TX
Henrov 8995RE
My mother 8995XX
右表中的代码可能不完整
1234AB Normal neigbourhood
3456 Bad neighbourhood
8995R Very good neighbourhood
我需要在邮政编码上加入这些表格。在这个例子中,输出必须是
John Smith Normal neighbourhood
Drew BarryMore Bad neighbourhood
Ted Bundy Bad neighbourhood
Henrov Very good neighbourhood
My mother -unknown-
所以我必须根据右表中邮政编码的长度来连接这两个表。
关于如何做到这一点的任何建议?我只能在 ON 语句中想出一个 CASE 但这不是很聪明;)
【问题讨论】:
-
你说的太对了,我编辑了。对不起。好像你比我更了解这个问题:)
标签: sql sql-server tsql sql-server-2012 string-comparison