Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hi to all I use SQL code on my t

Status
Not open for further replies.

VickyC

Technical User
Sep 25, 2010
206
CA
hi to all

I use SQL code on my tbl_1 to generate values for tbl_2, then I use an append query based on tbl_2 to generate values for tbl_3. My problem is that I'm sure tbl_2 is not necessary, but I can't figure out how to go from tbl_1 directly to tbl_3. Because I need to do this a lot, I want the process to be as efficient as possible.

Here are some details...
tbl_1 lists 5 distinct integers. (in the actual problem, there are more)

tbl_2 shows ALL PERMUTATIONS of the values in tbl_1. Because tbl_1 has 5 values in this example, tbl_2 has 5! = 120 rows. tbl_2 is NOT NORMALIZED, which is one of the reasons I hope to find out how to go from tbl_1 directly to tbl_3.

tbl_3 shows the data in tbl_2 in normalized form. 'Positions' have values 4, 3, 2, 1, 0, corresponding to P4, P3, P2, P1, P0. Because each record in tbl_2 has 5 data values, tbl_3 has 5 X 120 = 600 records.

Code:
[bb]
tbl_1        tbl_2                               tbl_3
(P is Int)  (P_ID is auto#, others integer)      (ID auto#, P_ID is Long, others Int)
  P          P_ID  P4  P3  P2  P1  P0             ID   P_ID   Position   P [/bb]
  42          1    16  42  45  83  94              1     1       4      16
  16          2    16  42  45  94  83              2     2       4      16
  33          3    16  42  83  45  94              3     3       4      16
  45          ... etc...                           4     4       4      16 
  94                                               ... etc ...
              ..........
             120   94  83  45  42  16            120   120      4      94
                                                 121     1      3      42
                                                 122     2      3      42
                                                 122     3      3      42
                                                  ... etc ...
                                                 240   120      3      83
                                                 241     1      2      45
                                                 242     2      2      45
                                                 243     3      2      83
                                                  ... etc ...

                                                  ...........
                                                 600   120      0      16

If there is SQL that goes would take the data in tbl_1 and INSERT it directly INTO tbl_3, avoiding the deNormalized intermediate step of tbl_2?

Thank you in advance for any thoughts.
Vicky C.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top