1
在下面的查詢中,我想檢索@MaximumRecords行,以便沒有任何ProjectId將行留在@MaximumRecords之外。限制SQL Server中的選定行
例如,如果@ MaximumRecords = 100,並且ProjectId = 7在99-102行有記錄,我希望僅檢索ProjectId = 1到ProjectId = 6的行(查詢將在稍後從ProjectId = 7)。我怎麼做?
SELECT TOP (@MaximumRecords)
t1.ProjectId,
t1.Row2,
t2.Row3
FROM Table1 t1
JOIN Table2 t2 ON t1.ProjectId = t2.ProjectId
ORDER BY
t1.ProjectId ASC
WHERE
t1.ProjectId > @InitialProjectId