Results 1 to 7 of 7
  1. #1
    jasonr704 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    4

    Need best method for creating query using same fields from multiple linked csv files?

    Currently I have created a new database with multiple linked tables. These are all individual csv files with identical headers.
    Here's the files:
    2013-jan-web.csv
    2013-jan-retail.csv
    2013-feb-web.csv


    2013-feb-retail.csv

    this continues for each month. Each day I export an update from our POS system that includes yesterdays sales. This just overwrites the current month 2013-sept-web.csv & 2013-sept-retail.csv.
    The files do not have exactly the same order of fields, but the field names are identical. The newer months have some additional fields added, so field order does not line up. All fields needed for this query are present in all months.

    GOAL:
    Create a query that is linked to all months and will refresh each time I run it, which is daily. I will only be pulling 8 of 25 fields for the query. Date, Amount, ShippingTotal, SKU, State, DiscountAmount, Coupon, NETRevenue
    I'd like to be able to see daily sales, monthly sales and then I'll be setting up YoY monthly reports.

    Any suggestions would be greatly appreciated!!!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    You are linking to the csv files, not importing and you are not retaining historical data? What is YoY?

    Maybe you need a UNION query. This will manipulate the data into a normalized, single dataset that can be used as source for other queries and manipulation. There is no designer for UNION, must build in the SQL View of query builder. Limit of 50 lines. Like:

    SELECT "Jan" AS Mo, "web" AS Source, field1, field2, field3, ... FROM 2013-jan-web.csv
    UNION SELECT "Feb", "retail", field1, field2, field3, ... FROM 2013-jan-retail.csv
    ...;
    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
    jasonr704 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    4

    here's the union query for selecting specific fields linked to multiple files

    Yes, I like the idea of creating a Union Query, however I'm not quite sure why it's not working. Here's what I have so far, but it's giving me a syntax error.

    SELECT "Jan" AS Mo, "web" AS Source, Order Date, Type, Component Total, Payment Method, Coupon Code, Discount Amount, Quantity, SKU, Brand Name, IP Holder, Device Size, Device Type, Manufacturer, Ship to State, Ship to Postal Code, Ship to Country, Affiliate, Partner Site, Skin, Device, Net Revenue, Design Code, Product Code, Product Name FROM [2013-jan-web]
    UNION SELECT "Feb" AS Mo, "retail" AS Source, Order Date, Type, Component Total, Payment Method, Coupon Code, Discount Amount, Quantity, SKU, Brand Name, IP Holder, Device Size, Device Type, Manufacturer, Ship to State, Ship to Postal Code, Ship to Country, Affiliate, Partner Site, Skin, Device, Net Revenue, Design Code, Product Code, Product Name FROM [2013-jan-retail];

    I get this message when I run it: "Syntax error in ORDER BY clause". I've also tried putting the linked tables in [ ] and that doesn't help.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    Any names with spaces or special characters/punctuation (underscore is exception) must be enclosed in []. This includes field names. This is why it is advised to avoid those features in naming as well as reserved words as 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.

  5. #5
    jasonr704 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    4
    I went in and changed all my source file field names, so there's no spaces. Just trying the first month and a few fields to see if I can get that to work.
    Now I'm running into this issue where I get the "Enter Parameter Value Box for Order_Date" box

    SELECT Order_Date, Type, Component_Total
    FROM [2013-jan-web]
    UNION ALL
    SELECT Order_Date, Type, Component_Total
    FROM [2013-jan-retail];

    By the way these tables are all linked csv files. Not sure if my syntax is fine as I have it.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    Can't just change the names in the query. The names must be the actual names in the object. So unless you can change the header names in the csv file, use []s in the query.
    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.

  7. #7
    jasonr704 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    4
    Yes, I did that. I changed the field names in each of the source files.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-13-2013, 12:00 PM
  2. Creating database from multiple HTML files
    By cupanther in forum Import/Export Data
    Replies: 1
    Last Post: 02-02-2013, 08:52 PM
  3. Replies: 11
    Last Post: 12-20-2012, 12:30 PM
  4. Replies: 19
    Last Post: 10-08-2012, 07:47 AM
  5. linked files
    By ashok in forum Access
    Replies: 2
    Last Post: 07-13-2012, 09:30 AM

Tags for this Thread

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