1

这是我未编译的更新语句:

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 作为别名。我怎样才能解决这个问题?

4

3 回答 3

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,',')
            )
于 2013-05-16T13:22:38.387 回答
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
...
于 2013-05-16T13:24:54.910 回答
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 WHERE d.DocumentID IN ( SELECT Data FROM dbo.Split(@DocumentIDs, ',') )

于 2013-05-16T13:25:50.437 回答