Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. [T-SQL] How to retrieve records from start index and count

[T-SQL] How to retrieve records from start index and count

Scheduled Pinned Locked Moved Database
databasetutorialalgorithmshelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hristiyan
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • H Hristiyan

      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.

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups