这是我的更新声明,未编译:
Update Documents d
Set
DocumentDate = 1,
LastStatusChangedDateTime = (
Select Top 1 DATEADD(ss,1,StatusChangedDateTime)
From [dbo].[DocumentStatusesHistory] dsh
Where dsh.DocumentID = d.DocumentID
)
Where DocumentID In
(
Select Data From dbo.Split(@DocumentIDs,',')
)
我无法将d用作别名。我该如何解决这个问题?
答案 0 :(得分:3)
这个怎么样?
Update Documents
Set
DocumentDate = 1,
LastStatusChangedDateTime = (
Select Top 1 DATEADD(ss,1,StatusChangedDateTime)
From [dbo].[DocumentStatusesHistory] dsh
Where dsh.DocumentID = d.DocumentID
)
From Documents d
Where DocumentID In
(
Select Data From dbo.Split(@DocumentIDs,',')
)
答案 1 :(得分:0)
添加FROM
子句:
Update d
Set
DocumentDate = 1,
LastStatusChangedDateTime = (
Select Top 1 DATEADD(ss,1,StatusChangedDateTime)
From [dbo].[DocumentStatusesHistory] dsh
Where dsh.DocumentID = d.DocumentID
)
FROM Documents AS d
...
答案 2 :(得分:0)
试试这个:
UPDATE d
SET d.DocumentDate = 1 ,
d.LastStatusChangedDateTime = ( SELECT TOP 1
DATEADD(ss, 1,
StatusChangedDateTime)
FROM [dbo].[DocumentStatusesHistory] dsh
WHERE dsh.DocumentID = d.DocumentID
)
FROM Documents d 在哪里d.DocumentID IN(选择数据 来自dbo.Split(@DocumentIDs,','))