Normalizing non-normal tables already containing data;OR changing columns into rows 
Author Message
 Normalizing non-normal tables already containing data;OR changing columns into rows

Hi Paul,

Quote:
> Unfortunately,
> the table contains one record for each item and has approx. 180 columns
> of measurement values. I would like to normalize this table...

Admirable goal! <g>

Quote:
>  However, there is no easy way of
> doing this.

One possibly too-tedious way would be to create an "append" query which
appends measurement1 to Measurement; then modify to append MeasureMent2 to
Measurement etc. Then repeat this 180 times. Not fun, but sometimes brute
force is the best way.

Quote:
> My other alternative is to write Access Basic
> DAO code (I'm in version 2.0), but I'm not quite sure how to write the
> procedure.

This wouldn't be too hard to do either. Theres a bruteforce method, and an
"elegant" method that may be more trouble than it's worth. Brute force:

  dim db as database
  dim rsBad as recordset
  dim rsMeasurements as recordset

  set db = currentdb()
  set rsBad = db.openrecordset("tblBadlyNormalizedData")
  set rsMeasurements = db.openrecordset("tblMeasurements")

  rsBad.movefirst
  do until rsBad.eof

    rsMeasurements.addnew
    rsMeasurements!id = rsBad!ID
    rsMeasurements!Measurement = rsBad!Measurement1
    rsMeasurements.update

    rsMeasurements.addnew
    rsMeasurements!id = rsBad!ID
    rsMeasurements!Measurement = rsBad!Measurement2
    rsMeasurements.update

    rsMeasurements.addnew
    rsMeasurements!id = rsBad!ID
    rsMeasurements!Measurement = rsBad!Measurement3
    rsMeasurements.update

    rsBad.movenext

   'etc
  loop

With cut-and-paste this might not be too bad.

You could also loop through the "fields" collection of the recordset and
add the rows that way. I'll spare you (and me) the example for this unless
you need help with it.

--
-- Jim F, FMS
    http://www.*-*-*.com/



Tue, 22 Jun 1999 03:00:00 GMT  
 Normalizing non-normal tables already containing data;OR changing columns into rows

Paul--

To expand on Jim's second thought:

    For i = 1 to 180
        rsMeasurements.addnew
        rsMeasurements!id = rsBad!ID
        rsMeasurements!Seq = i
-->    rsMeasurements!Measurement = rsBad("Measurement" & Trim(Str(i)))
        rsMeasurements.update
   Next i

I use the "parenthesis" method of referencing a control/Field all the time.
 Since tables in a releational database can not be made up of arrays, all
you have to do is concatonate the index onto the control/field name.

Hope this helps!

--Tom



Tue, 22 Jun 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to sort dataview table on string datatype column contains all numbers:

2. RDO: Connecting to SQL server table containing an identity column

3. Error Check to Test For Same Data Already in Table

4. normalising table with a fields containing CSV data

5. Function to return data contained in a table

6. Changing a field to Read only when form sent if it contains data

7. How to find out if table contains data?

8. Normalizing a flat table w/VBA

9. Working wit Normalized Table

10. Working with Normalized Table

11. Normalizing a table with VBA

12. macro for converting EMF tables in Word to normal cellular Tables

 

 
Powered by phpBB® Forum Software