I have a parent table (Person) with a child table (Address). I need to send all person and address combinations to a service to be processed, but I am restricted in that I can only send up to 10,000 at a time. When I send data for a person I need to make sure I send all of the data for that person, so they can’t be split across batches.
I want to be able to pull the data using SQL only, no additional code (this is to be used in an SSIS package).
Example: I want to pull only max of 5 from the data below
---Person--- ---------Address----------
ID Name AddressID Address
--- -------- ------------ -------------
1 Bill 1 1 The Street
1 Bill 2 3 The Road
2 Jeff 3 7 The Hill
3 Mike 4 9 The Avenue
4 Ross 5 11 Main Road --- This is the 5th row, must be ignored
4 Ross 6 12 Down Under --- This record would be orphaned if
we pulled top 5
I found this seemed to be the best way to do it:
The TOP 10001 allows me to limit the data searched as if the 10000th and 10001st record share a parent, then the 10000th should be ignored.