我希望使用现有值加5年更新NULL值的日期列,PK为IdentityCourseID
。
这就是我想要实现的目标:
UPDATE IdentityCourses
SET Expiry = DATEADD(year, 5, IdentityCourses.DateAttained)
WHERE IdentityCourseID = (SELECT IdentityCourseID
FROM IdentityCourses
INNER JOIN UnitIdentities ON IdentityCourses.IdentityID = UnitIdentities.IdentityID
WHERE (IdentityCourses.CourseID = 1041)
AND (UnitIdentities.IsActiveMember = 1)
AND (UnitIdentities.EndDate IS NULL)
AND (IdentityCourses.Expiry IS NULL) )
答案 0 :(得分:0)
我认为这对你有用:
UPDATE ic
SET Expiry = DATEADD(year, 5, ic.DateAttained)
FROM IdentityCourses AS ic
INNER JOIN UnitIdentities AS ui
ON ic.IdentityID = ui.IdentityID
WHERE ic.CourseID = 1041
AND ui.IsActiveMember = 1
AND ui.EndDate IS NULL
AND ic.Expiry IS NULL