这是我不正确的查询:
;With normal As
(
Select ROW_NUMBER() Over (Order by RecordingDateTime) as RowNum,
DocumentID,
CreatedByAccountID,
JurisdictionID,
InstrumentID
-- Cast(InstrumentID as decimal(18)) as InstrumentID
From Documents Where RecordingDateTime IS NOT NULL
)
Select Top 1 @PreviousInstrumentID = InstrumentID,
@PreviousDocumentID = DocumentID,
@PreviousCreatedByAccountID = CreatedByAccountID,
@PreviousBelongsToJurisdictionID = JurisdictionID
From normal
Where RowNum = @RowNum - 1
Select Top 1 @NextInstrumentID = InstrumentID,
@NextDocumentID = DocumentID,
@NextCreatedByAccountID = CreatedByAccountID,
@NextBelongsToJurisdictionID = JurisdictionID
From normal
Where RowNum = @RowNum + 1
我希望两个 select 语句都在 CTE 的上下文中。我如何做到这一点?