我已将过期日期从一个表移到另一个表。由于我创建了新列,因此添加了一些新日期,但大多数仍设置为NULL。
我需要将原始表和列(a)中的日期复制到新表和列(b),前提是b为NULL且标记为系统。
我创建了以下语句,但是它会抛出错误。我想我可能不得不使用FROM,但我对T-SQL比较新,并且之前没有经验。有没有人知道我犯了哪些错误?
UPDATE purchs
SET purchs.dexpiredate = client.dexpire
FROM
INNER JOIN client ON client.iclientid = purchs.iclientid
INNER JOIN feature ON purchs.ifeatureid = feature.ifeatureid
WHERE feature.lsystem = 1 and purchs.dexpiredate IS NULL
GO
答案 0 :(得分:2)
UPDATE p
SET p.dexpiredate = c.dexpire
FROM purchs p
INNER JOIN client c ON c.iclientid = p.iclientid
INNER JOIN feature f ON f.ifeatureid = p.ifeatureid
WHERE
f.lsystem = 1 and
p.dexpiredate IS NULL