これは適切ではない私のクエリです:
;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のコンテキストで使用する必要があります。どうすればそれを達成できますか?