Results 1 to 3 of 3
  1. #1
    Deutz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    51

    Update table with different layout

    Thanks in advance. I have two tables, table 1 and table 2 as per below. I want to update table 2 with values from the Cost and Parts fields in Table 1.



    My question is, how would I match up the fields so that the data ends up in the right slots?


    Table 1:

    Code:
    ForeignKey|Type|Range|Cost|Parts
    202|A|1|$10|120 
    202|A|2|$50|10 
    202|B|1|$100|30 
    202|B|2|$5|0



    Table 2 prior to data entered from Table 1:

    Code:
    ForeignKey|FieldNm|Range|A|B
    202|Cost|1|| 
    202|Cost|2|| 
    202|Parts|1|| 
    202|Parts|2||



    Desired result: Table 2 after data entered from Table 1:

    Code:
    ForeignKey|FieldNm|Range|A|B
    202|Cost|1|$10|$100 
    202|Cost|2|$50|5 
    202|Parts|1|120|30 
    202|Parts|2|10|0


    Rgds
    Deutz

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Using the sample data, can get the result of table 2 with:

    SELECT ForeignKey, Type, Range, "Cost" As FieldNm,Cost As Amount FROM Table1
    UNION SELECT ForeignKey, Type, Range, "Parts", Parts FROM Table1;

    TRANSFORM First([Amount]) AS FirstOfAmount
    SELECT [ForeignKey], [FieldNm], [Range]
    FROM Query1
    GROUP BY [ForeignKey], [Range], [FieldNm]
    PIVOT [Type];

    There is no wizard or designer for UNION query. Must type in the SQL View window of the query designer.

    Since a query can produce the desired output, not really necessary to maintain another table. However, if you must, then use the CROSSTAB query as source for an UPDATE SQL.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Deutz is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    51
    Thanks June7

    I'll give it a go and see if I can get it working.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-22-2011, 02:48 PM
  2. Needing Advice and Help with Table Layout
    By PeteW in forum Database Design
    Replies: 0
    Last Post: 03-12-2011, 11:40 PM
  3. Replies: 1
    Last Post: 01-22-2011, 12:23 PM
  4. Help needed with table design/layout for newbie
    By jase118 in forum Database Design
    Replies: 8
    Last Post: 06-05-2010, 02:59 AM
  5. Table Layout Question
    By WonkeyDonkey in forum Database Design
    Replies: 6
    Last Post: 11-22-2005, 08:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums