Quantcast
Channel: How to select the nth row in a SQL database table? - Stack Overflow
Viewing all articles
Browse latest Browse all 35

Answer by nPcomp for How to select the nth row in a SQL database table?

$
0
0

For SQL server, the following will return the first row from giving table.

declare @rowNumber int = 1;    select TOP(@rowNumber) * from [dbo].[someTable];EXCEPT    select TOP(@rowNumber - 1) * from [dbo].[someTable];

You can loop through the values with something like this:

WHILE @constVar > 0BEGIN    declare @rowNumber int = @consVar;       select TOP(@rowNumber) * from [dbo].[someTable];    EXCEPT       select TOP(@rowNumber - 1) * from [dbo].[someTable];         SET @constVar = @constVar - 1;    END;

Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>