Results 1 to 3 of 3
  1. #1
    mork283 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    2

    Separating implicit data from Access table formatted like an Excel table

    Good afternoon,

    I've inherited an Access database containing tables formatted more like Excel tables. The table I'm working on now looks like...

    PK Year Profit Center SalesmanID January Units February Units March Units etc... January Margin February Margin March Margin etc...
    1 2016 5 15 5,000 7,500 6,500 ... 55.25 51.50 53.00 ...

    I tried a union query to reorganize the data by month and type (units or margin), but I wasn't able to keep the PK, Year, Profit Center and SalesmanID as they were. So, I'm looking for tips on how to get my data into the following format.

    PK Year Month Profit Center SalesmanID Units Margin
    1 2016 1 5 15 5,000 55.25
    1 2016 2 5 15 7,500 51.50
    1 2016 3 5 15 6,500 53.00

    Any suggestions?

    Thanks,

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What do you mean by "wasn't able to keep the PK, Year, Profit Center and SalesmanID as they were" - why not? A UNION query should provide the desired output. Post the attempted query. Something like:

    SELECT PK, [Year], 1 AS [Month], [Profit Center], SalesmanID, [January Units] AS Units, [January Margin] AS Margin FROM tablename
    UNION SELECT PK, [Year], 2, [Profit Center], SalesmanID, [February Units], [February Margin] FROM tablename
    ...
    UNION SELECT PK, [Year], 12, [Profit Center], SalesmanID, [December Units], [December Margin] FROM tablename;

    Year and Month are reserved words and should not use reserved words as names for anything. Also advise no spaces or punctuation/special characters (underscore only exception) in names.
    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
    mork283 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Posts
    2
    To answer your first question, turns out I just had the format incorrect in my initial Select and saw it when I compared to your query. The rest works like a charm! Thank you!

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

Similar Threads

  1. Replies: 2
    Last Post: 01-12-2017, 10:35 AM
  2. Update Excel data from access table through SQL in VBA
    By anandagrawal444 in forum Access
    Replies: 2
    Last Post: 11-20-2015, 12:59 PM
  3. Replies: 4
    Last Post: 03-19-2015, 06:14 PM
  4. VBA - Import Excel Data into Access Table
    By sikhinvestor in forum Import/Export Data
    Replies: 2
    Last Post: 04-28-2014, 01:43 PM
  5. Separating information in a table
    By Lupson2011 in forum Queries
    Replies: 27
    Last Post: 05-15-2012, 06:36 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