[T-SQL] How to retrieve records from start index and count
-
I'm searching for logic which will help me to retrieve table records based on "start index" parameter and parameter which specifies the returned records count. Example: dbo.Records num 1 2 3 4 5 SELECT num FROM dbo.Records will return 5 records. I cant find a function or something other which will help me retrieve the following logic input params : @startIndex = 2 , @recordsCount = 2 so when i perform the select statement to retrieve the 2 records (3 and 4) If there is no answer with an exact function, is there a wordaraund ? Please help. Regards Hris.
-
I'm searching for logic which will help me to retrieve table records based on "start index" parameter and parameter which specifies the returned records count. Example: dbo.Records num 1 2 3 4 5 SELECT num FROM dbo.Records will return 5 records. I cant find a function or something other which will help me retrieve the following logic input params : @startIndex = 2 , @recordsCount = 2 so when i perform the select statement to retrieve the 2 records (3 and 4) If there is no answer with an exact function, is there a wordaraund ? Please help. Regards Hris.
try this ...
select top @recordsCount num from dbo.records where num >= @startIndex
You may also be able to use something like this ...select num from dbo.records where (num >= @startIndex) and (num <= @startIndex + @recordCount)
I haven't tested it, but it is probably close.