Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2010
    Location
    Atlanta, GA
    Posts
    211
    Provided Answers: 1

    Unanswered: Break data-set into groups of 5000 records

    I have a large data set that I want to split into groups of 5000 records so if there are 11000 rows in the table, rows 1 thru 5000 will be labeled 1, 5001 thru 10000 labeled 2, and 10001 thru 11000 labeled 3.

    I use NTILE() a lot but that clearly doesnt work in this instance. I am thinking of dividing the row number by 5000 and that result+1 (ignoring the remainder) would be it's group number. Perhaps there is a better way? Maybe a different window function in SQL 2012?

  2. #2
    Join Date
    Oct 2010
    Location
    Atlanta, GA
    Posts
    211
    Provided Answers: 1
    OK, i think I answered my own question. Select *, (row_number() over(order by newid())/5000 as GroupNumber

    I used newid() because i wanted random groupings.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •