jacobly
04-23-2007, 02:01 PM
I have a table with the a structure similar to the following
id | section | subsection | division | group | subgroup | officialName | Name
--------------------------------------------------------------------------------------
01 | 33 | 001 | 00 | 00 | 00 | Book1 | Book
02 | 33 | 001 | 01 | 00 | 00 | NULL | dsf
03 | 33 | 001 | 01 | 01 | 00 | Book3 | Report
04 | 33 | 001 | 01 | 01 | 99 | NULL | NULL
05 | 33 | 001 | 01 | 02 | 00 | Document1 | document
06 | 33 | 001 | 01 | 02 | 01 | NULL | NULL
07 | 33 | 001 | 01 | 03 | 00 | Document3 | unknown
08 | 33 | 001 | 01 | 03 | 99 | NULL | NULL
09 | 33 | 001 | 01 | 04 | 00 | Document4 |
10 | 33 | 001 | 01 | 04 | 99 | NULL |
What I need to do is clean up my data by performing inserts on data which shares similar charaterisitics.
For example, in the above table, I need to copy the official name from row 03 to the same position in row 04. Essentially using section, subsection, division, and group as a combined key to select:
id | section | subsection | division | group | subgroup | officialName | Name
--------------------------------------------------------------------------------------
03 | 33 | 001 | 01 | 01 | 00 | Book3 | Report
04 | 33 | 001 | 01 | 01 | 99 | NULL | NULL
and end up with:
id | section | subsection | division | group | subgroup | officialName | Name
--------------------------------------------------------------------------------------
03 | 33 | 001 | 01 | 01 | 00 | Book3 | Report
04 | 33 | 001 | 01 | 01 | 99 | Book3 | Report
or in the final resulting data after running the query on the whole table:
id | section | subsection | division | group | subgroup | officialName | Name
--------------------------------------------------------------------------------------
01 | 33 | 001 | 00 | 00 | 00 | Book1 | Book
02 | 33 | 001 | 01 | 00 | 00 | NULL | dsf
03 | 33 | 001 | 01 | 01 | 00 | Book3 | Report
04 | 33 | 001 | 01 | 01 | 99 | Book3 | Report
05 | 33 | 001 | 01 | 02 | 00 | Document1 | document
06 | 33 | 001 | 01 | 02 | 01 | Document1 | document
07 | 33 | 001 | 01 | 03 | 00 | Document3 | unknown
08 | 33 | 001 | 01 | 03 | 99 | Document3 | unknown
09 | 33 | 001 | 01 | 04 | 00 | Document4 | blank
10 | 33 | 001 | 01 | 04 | 99 | Document4 | blank
Thanks in advance for any help!
Let me know if I need to further clarify my question.
Jacob
id | section | subsection | division | group | subgroup | officialName | Name
--------------------------------------------------------------------------------------
01 | 33 | 001 | 00 | 00 | 00 | Book1 | Book
02 | 33 | 001 | 01 | 00 | 00 | NULL | dsf
03 | 33 | 001 | 01 | 01 | 00 | Book3 | Report
04 | 33 | 001 | 01 | 01 | 99 | NULL | NULL
05 | 33 | 001 | 01 | 02 | 00 | Document1 | document
06 | 33 | 001 | 01 | 02 | 01 | NULL | NULL
07 | 33 | 001 | 01 | 03 | 00 | Document3 | unknown
08 | 33 | 001 | 01 | 03 | 99 | NULL | NULL
09 | 33 | 001 | 01 | 04 | 00 | Document4 |
10 | 33 | 001 | 01 | 04 | 99 | NULL |
What I need to do is clean up my data by performing inserts on data which shares similar charaterisitics.
For example, in the above table, I need to copy the official name from row 03 to the same position in row 04. Essentially using section, subsection, division, and group as a combined key to select:
id | section | subsection | division | group | subgroup | officialName | Name
--------------------------------------------------------------------------------------
03 | 33 | 001 | 01 | 01 | 00 | Book3 | Report
04 | 33 | 001 | 01 | 01 | 99 | NULL | NULL
and end up with:
id | section | subsection | division | group | subgroup | officialName | Name
--------------------------------------------------------------------------------------
03 | 33 | 001 | 01 | 01 | 00 | Book3 | Report
04 | 33 | 001 | 01 | 01 | 99 | Book3 | Report
or in the final resulting data after running the query on the whole table:
id | section | subsection | division | group | subgroup | officialName | Name
--------------------------------------------------------------------------------------
01 | 33 | 001 | 00 | 00 | 00 | Book1 | Book
02 | 33 | 001 | 01 | 00 | 00 | NULL | dsf
03 | 33 | 001 | 01 | 01 | 00 | Book3 | Report
04 | 33 | 001 | 01 | 01 | 99 | Book3 | Report
05 | 33 | 001 | 01 | 02 | 00 | Document1 | document
06 | 33 | 001 | 01 | 02 | 01 | Document1 | document
07 | 33 | 001 | 01 | 03 | 00 | Document3 | unknown
08 | 33 | 001 | 01 | 03 | 99 | Document3 | unknown
09 | 33 | 001 | 01 | 04 | 00 | Document4 | blank
10 | 33 | 001 | 01 | 04 | 99 | Document4 | blank
Thanks in advance for any help!
Let me know if I need to further clarify my question.
Jacob