[AccessD] Divide A Table into 4 equal parts and append to a secondtable

Gustav Brock Gustav at cactus.dk
Mon Nov 29 03:25:44 CST 2004


Hi Tom

I guess you could pick every fourth record as base ID for a selection
and create subselects to collect data from four records along these
lines:

<SQL>

  SELECT DISTINCT 
    ID\4 AS ID4, 
      (Select 
        T.FieldSome 
      From 
        tblYourTable As T 
      Where 
        T.ID\4 = tblYourTable.ID\4 
        And 
        T.ID Mod 4 = 0) AS 
    A, 
      (Select 
        T.FieldSome 
      From 
        tblYourTable As T 
      Where 
        T.ID\4 = tblYourTable.ID\4 
        And 
        T.ID Mod 4 = 1) AS 
    B, 
      (Select 
        T.FieldSome 
      From 
        tblYourTable As T 
      Where 
        T.ID\4 = tblYourTable.ID\4 
        And 
        T.ID Mod 4 = 2) AS 
    C, 
      (Select 
        T.FieldSome 
      From 
        tblYourTable As T 
      Where 
        T.ID\4 = tblYourTable.ID\4 
        And 
        T.ID Mod 4 = 3) AS 
    D
  FROM 
    tblYourTable;

</SQL>

This assumes that your IDs are truly sequential (no "holes"). If this
is not the case, things get a little more complicated.
Also, first ID should be 0. If not, you will need to move around the
sequence of A to D and their modulos - from 0,1,2,3 to 1,2,3,0 if the
first ID is 1.

/gustav



More information about the AccessD mailing list