我有以下查詢SQL服務器遞歸查詢更新
WITH PersonCTE
AS
(
SELECT
[ParentId],
[Id],
[Name],
[LastDeleted],
[LastRestored],
[EntryTime]
FROM [dbo].[Backup]
WHERE [Id] = someguid
UNION ALL
SELECT
c.ParentId,
c.Id,
c.Name,
c.LastDeleted,
c.LastRestored,
c.EntryTime
FROM [dbo].[Backup] c
INNER JOIN PersonCTE s
ON c.ParentId = s.Id
)
SELECT *
FROM PersonCTE
需要在事後做這種更新:
UPDATE Backup
SET [LastRestored] = GETDATE
我希望能夠設置LastRestored
到GETDATE
只受影響的結果的行。
您是否嘗試過加入'Backup'你的CTE和執行更新? – Taryn 2015-02-09 17:47:47