您好,两个表格中的数据示例:
我有两列的表MSISDNs_for_Import:
msisdn sim
359898855753 99085719352
我的另一个表是SIMs_for_Import,其中包含这两列:
IMSI SIMNO
284010160719352 8935901990857193529
我的问题是我该如何使用第二个表列simno的值更新我的第一个表列sim
我正在尝试以下查询:
UPDATE MSISDNs_for_Import
SET MSISDNs_for_Import.sim=
(SELECT SIMs_for_Import.SIMNO
FROM SIMs_for_Import
WHERE MSISDNs_for_Import.sim=SIMs_for_Import.SIMNO )
但是它将空值保存在MSISDNs_for_Import.sim列中
答案 0 :(得分:0)
我认为您可能正在寻找类似的东西。
UPDATE ms
SET
ms.sim= si.SIMNO
FROM
MSISDNs_for_Import ms
INNER JOIN SIMs_for_Import si
ON ms.sim = LEFT(RIGHT(si.SIMNO, LENGTH(ms.sim) + 1), LENGTH(ms.sim))
答案 1 :(得分:0)
尝试一下
UPDATE MSISDNs_for_Import a
JOIN
SIMs_for_Import b
SET
a.sim = SUBSTRING(b.SIMNO, 8, 12)
WHERE
a.sim = SUBSTRING(b.SIMNO, 8, 11);