title: TSQL Group/Split Together in Multiple of X based on Variable Column Values
body: <p>I want the following dataset to be grouped or split based on 'Drv_uniqId'. </p>
  
  <p>The relationship between <code>Drv_uniqId</code> and <code>Trk_uniqId</code> can be one-2-one or one-2-many (upto a maximum of 10). That is one <code>Drv_uniqId</code> can be assigned to upto 10 <code>Trk_uniqId</code></p>
  
  <p>The relationship between <code>Trk_uniqId</code> and <code>Drv_uniqId</code> can be one-2-one or one-2-many (upto a maximum of 4). That is one <code>Trk_uniqId</code> can be assigned to upto 4 <code>Drv_uniqId</code></p>
  
  <p>The data can consist of all unique <code>Drv_uniqId</code> and <code>Trk_uniqId</code> combinations. I am to show this data in a report and I can't show one row on each page. The Group/split will be used in SSRS to split the final report into multiple pages. </p>
  
  <p><strong>Rules</strong></p>
  
  <p>Each <code>Drv_uniqId</code> must within the same Group. Can not be split over multiple groups.</p>
  
  <p>Each group = Minimum 5 rows and maximum 10 rows</p>
  
  <p>DDL</p>
  
  <pre><code>SELECT *
  FROM (VALUES
  (1,530,'4392 T_01'),
  (2,540,'4209 H_01'),
  (3,540,'4551 T_01'),
  (4,543,'4407 T_01'),
  (5,543,'4691 T_01'),
  (6,546,'4691 T_01'),
  (7,546,'4579 T_01'),
  (8,757,'4688 T_01'),
  (9,757,'4689 T_01'),
  (10,757,'4691 T_01'),
  (11,757,'4407 T_01'),
  (12,855,'4410 T_01'),
  (13,1249,'4583 A_01'),
  (14,1324,'4689 T_01'),
  (15,1324,'4690 T_01'),
  (16,1411,'4689 T_01'),
  (17,1411,'4690 T_01'),
  (18,1411,'4478 A_01'),
  (19,1411,'4411 T_01'),
  (20,1411,'4692 T_01'),
  (21,1411,'4406 T_01'),
  (22,2115,'4410 T_01'),
  (23,2115,'4414 T_01'),
  (24,2115,'4422 T_01'),
  (25,2325,'3422 T_01') ,
  (26,2325,'4522 T_01') ,
  (27,2330,'4462 T_01')   ) tbl (Id,Drv_uniqId,Trk_uniqId) 
  </code></pre>
  
  <p>I've removed the sample expected output as it doesn't matter what group any <code>Drv_uniqId</code> goes in just as long as they don't exist in multiple groups - any solution doesn't have to match this output just the rules.
  Minimum 5 and maximum 10</p>