OK, that makes sense... Unfortunately there is a bit of a problem, in that you think there is a "4th row" etc, when there really isn't.
The database can (and will) return data in any order it sees fit at that particular moment. Even if it returns a set of records in the same order 1000 times, it could return them in a completely different order next time (and that does happen!).
If the order matters to you at all, the way to deal with it is to use an Order By clause, which specifies the field(s) to sort it by - hence my "for the 5th lowest value of LIN" comment.
Assuming that you do want it sorted by Lin, I think this should work:
(replace the 4 with the row number you want)Code:SELECT TOP 1 ID_LINE AS COMMENT_5 FROM ( SELECT TOP 4 Lin, ID_LINE FROM PK5.dbo.ID WHERE ID_IMKEY = @partNo ORDER BY Lin ) ORDER BY Lin DESC




Reply With Quote