Re: how to minimize DataTable size with SQL specified rows?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee

    Re: how to minimize DataTable size with SQL specified rows?

    It's been a long time since I wrote SQL in SQL Server (My company is
    an Oracle shop) but I remember being able to use the TOP and BOTTOM
    keywords to get a set of data.

    So, if you wanted the 21 thru 40th record:

    SELECT BOTTOM 20
    *
    FROM
    (SELECT TOP 40
    *
    FROM
    MyTable
    WHERE
    ....
    )

    So in essence, you select your max number, then from that selection
    you select your final grouping, i.e.,

    If these were the records:

    1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,15,16,17,18, 19,20,21,22,23, 24,25,26,27,28, 29,30,31,32,33, 34,35,36,37,38, 39,40,41,42,43, 44,45,46,47,48, 49, ....

    the select with the TOP clause limits the data to:

    1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,15,16,17,18, 19,20,21,22,23, 24,25,26,27,28, 29,30,31,32,33, 34,35,36,37,38, 39,40

    by getting the top 40 records, then the select with the BOTOM clause
    futher limits the data to:

    21,22,23,24,25, 26,27,28,29,30, 31,32,33,34,35, 36,37,38,39,40

    by getting the last 20 records from the prior select.

    I'm sure that there are many newer and better ways too do this now -
    especially if you are wanting to use Stored Procs., but this is how to
    do it "Old School".

    Hope this helps,
    L. Lee Saunders
    Playing with old ideas/concepts using the newest tools!

  • =?Utf-8?B?UiBSZXllcw==?=

    #2
    Re: how to minimize DataTable size with SQL specified rows?

    Awesome! Will give it a shot and have no doubt that it will work from the
    way you explained.

    Thank you

    "Lee" wrote:
    It's been a long time since I wrote SQL in SQL Server (My company is
    an Oracle shop) but I remember being able to use the TOP and BOTTOM
    keywords to get a set of data.
    >
    So, if you wanted the 21 thru 40th record:
    >
    SELECT BOTTOM 20
    *
    FROM
    (SELECT TOP 40
    *
    FROM
    MyTable
    WHERE
    ....
    )
    >
    So in essence, you select your max number, then from that selection
    you select your final grouping, i.e.,
    >
    If these were the records:
    >
    1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,15,16,17,18, 19,20,21,22,23, 24,25,26,27,28, 29,30,31,32,33, 34,35,36,37,38, 39,40,41,42,43, 44,45,46,47,48, 49, ....
    >
    the select with the TOP clause limits the data to:
    >
    1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,15,16,17,18, 19,20,21,22,23, 24,25,26,27,28, 29,30,31,32,33, 34,35,36,37,38, 39,40
    >
    by getting the top 40 records, then the select with the BOTOM clause
    futher limits the data to:
    >
    21,22,23,24,25, 26,27,28,29,30, 31,32,33,34,35, 36,37,38,39,40
    >
    by getting the last 20 records from the prior select.
    >
    I'm sure that there are many newer and better ways too do this now -
    especially if you are wanting to use Stored Procs., but this is how to
    do it "Old School".
    >
    Hope this helps,
    L. Lee Saunders
    Playing with old ideas/concepts using the newest tools!

    >

    Comment

    Working...