我想选择列和连接表,其中连接条件连接所选列以及点。例如,
SELECT TBL1.ID,
TBL1.COUNTRY As A,
TBL1.STATE As B,
TBL1.CODE As C
FROM TBL1, TBL2
WHERE TBL2.ID = A+'.'+B+'.'+C
数据是TBL2.ID
看起来像' US.NY.61 ',其中美国是TBL1.COUNTRY
, NY < / strong>是TBL1.STATE
等等。
更新:SQl小提琴:http://sqlfiddle.com/#!3/26b6b/4
答案 0 :(得分:0)
尝试这样的事情怎么样
SELECT TBL1.ID,
TBL1.COUNTRY As A,
TBL1.STATE As B,
TBL1.CODE As C
FROM TBL1
INNER JOIN TBL2 ON CAST(TBL1.COUNTRY AS varchar(20)) + '.' + CAST(TBL1.STATE AS varchar(20)) + '.' + CAST(TBL1.CODE AS varchar(20)) = CAST(TBL2.ID AS varchar(20))
添加代码以在合并和比较它们之前将4个字段强制转换为varchar。
答案 1 :(得分:0)
SELECT T.name,T2.nam FROM
T INNER JOIN T2
ON T.id = (T2.one + '.' + CAST(T2.two as varchar(50)) + '.' + CAST( T2.thr as varchar(50) ))