TSQL SELECT Question RRS feed

  • Question

  • User297669845 posted
    I want to get results from a specified row to another specified row like: row 1 to row 10 row 11 to row 20 i don't know how the TSQL code would look like: SELECT FROM [myTable] FROM ROW 1 TO ROW 10 first i tried a column with the following info: Datatype: int Identity: Yes Seed: 1 Identity Increment: 1 and tried the following TSQL code: SELECT [id], [Column1], [Column2], [Column3] FROM [myTable] WHERE [id] >= '1' AND [id] >= '10' But it failed when i deleted some rows. Now I wanna change the SELECT form to an appropriate one. Thanks
    Friday, December 17, 2004 4:34 AM

All replies

  • User1281985059 posted
    Google for something like 'Page results from stored procedure'. Also, search this forum; there's been several posts about doing it. A couple different ways, but it's been discusses at great length. Search, you'll find it.
    Friday, December 17, 2004 8:51 AM
  • User-1786411686 posted
    for numeric columns you dont need to put quotes around the value.. besides the pdraigh's suggestion you could try SELECT [id], [Column1], [Column2], [Column3] FROM [myTable] WHERE [id] >= 1 AND [id] <= 10 in your query analyzer hth
    Friday, December 17, 2004 9:55 AM
  • User157729769 posted
    If you count on the ID field as you have described you will always have a problem whenever any data is deleted as there will be holes in the sequentil numbering in the field. In order to get the exact number of records in the exact sequence specified (and I think that is waht you are after) create a temporary table with an identity field, then do select into the temp table and lastly do a select now based on the ID. Cheers
    Thursday, December 23, 2004 1:05 AM
  • User-1784332293 posted

    try this

    select * from (select *,ROW_NUMBER() over (order by getdate()) as rno from yourTable) t where rno between 1 and 10

    Friday, April 24, 2015 1:26 PM