Split delimited entries into new rows in Access

前端 未结 3 1327
执笔经年
执笔经年 2021-01-20 10:02

So someone gave me a spreadsheet of orders, the unique value of each order is the PO, the person that gave me the spreadsheet is lazy and decided for orders with multiple PO

3条回答
  •  盖世英雄少女心
    2021-01-20 10:19

    About about this:

    1) Import the source data into a new Access table called SourceData.

    2) Create a new query, go straight into SQL View and add the following code:

    SELECT * INTO ImportedData
    FROM (
      SELECT PO, Vendor, State
      FROM SourceData
      WHERE InStr(PO, '/') = 0
      UNION ALL
      SELECT Left(PO, InStr(PO, '/') - 1), Vendor, State
      FROM SourceData
      WHERE InStr(PO, '/') > 0
      UNION ALL
      SELECT Mid(PO, InStr(PO, '/') + 1), Vendor, State
      FROM SourceData
      WHERE InStr(PO, '/') > 0) AS CleanedUp;
    

    This is a 'make table' query in Access jargon (albeit with a nested union query); for an 'append' query instead, alter the top two lines to be

    INSERT INTO ImportedData
    SELECT * FROM (
    

    (The rest doesn't change.) The difference is that re-running a make table query will clear whatever was already in the destination table, whereas an append query adds to any existing data.

    3) Run the query.

提交回复
热议问题