+ Reply to Thread
Results 1 to 6 of 6

Inventory Update - Updated rows from one table to another & add rows for new orders

  1. #1
    Registered User
    Join Date
    07-01-2013
    Location
    Berlin
    MS-Off Ver
    Excel 2007
    Posts
    4

    Inventory Update - Updated rows from one table to another & add rows for new orders

    Hi dear Forum! This my first post, so bear with me for any mistakes I make or conventions I do not observe (unintentionally, of course )

    I would like to achieve the following:

    I have an Inventory of mobile phones (ca. 15000 entries), which is stored as a table in Access and contains information like Number, First Name, Last Name, Email, Tariff, Contract Start Date/End Dates.

    I receive weekly a table with a summary of orders (ca. 20 per week), which include: changes to User Details, Tariffs, Contract Start/Ending Dates and new orders.

    Now I would have to have to updates: one to add the new numbers as rows, and one to update the relevant fields for the existing numbers.

    I have created two queries:

    One two add the new numbers:

    INSERT INTO InventoryReportRaw ( [Mobile Number], Tariff, [Cost Centre], [Contract end date], [Activation date], [First Name], [Last Name], Email )
    SELECT OrderReport.EndUserNr, OrderReport.Tariff, OrderReport.CostCentre, OrderReport.ContractEndDate, OrderReport.FutureActivationDate, OrderReport.EndUserFirstName, OrderReport.EndUserLastName, OrderReport.EndUserEmail
    FROM OrderReport, InventoryReportRaw
    WHERE (((OrderReport.TransactionType)="Change-BAN") AND ((OrderReport.Status)="Completed")) OR (((OrderReport.TransactionType)="CTN-PortingIn") AND ((OrderReport.Status)="Completed")) OR (((OrderReport.TransactionType)="CTN-TransferIn") AND ((OrderReport.Status)="Completed")) OR (((OrderReport.TransactionType)="Svc-Delivery") AND ((OrderReport.Status)="Completed"));

    And one to update existing fields:

    UPDATE OrderReport RIGHT JOIN InventoryReportRaw ON OrderReport.EndUserNr = InventoryReportRaw.[Mobile Number] SET InventoryReportRaw.[Last Name] = [OrderReport].[EndUserLastName], InventoryReportRaw.[First Name] = [OrderReport].[EndUserFirstName], InventoryReportRaw.Email = [OrderReport].[EndUserEmail], InventoryReportRaw.Tariff = [OrderReport].[Tariff], InventoryReportRaw.[Contract end date] = [OrderReport].[closure date], InventoryReportRaw.[Contract end date] = [OrderReport].[closure date]
    WHERE (((OrderReport.TransactionType)="Svc-chg-details" Or (OrderReport.TransactionType)="Svc-chg-details" Or (OrderReport.TransactionType)="Svc-chg-details" Or (OrderReport.TransactionType)="Svc-Chg-Tariff" Or (OrderReport.TransactionType)="Terminate-Nr" Or (OrderReport.TransactionType)="CTN-TransferOut") AND ((OrderReport.Status)="Completed"));

    When I run the queries, Access tells me it is going to Append/Update over 100000 records - which just cannot be true.

    Do you have any suggestions as to how I can solve my problem? I am open to any tips!

    Thanks in advance,

    werderexpat

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: Inventory Update - Updated rows from one table to another & add rows for new orders

    What happens when you run the query? If you haven't run it yet, then make a backup and run it. See if the results are as expected.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-01-2013
    Location
    Berlin
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Inventory Update - Updated rows from one table to another & add rows for new orders

    Hi! Thanks for your answer!

    If I run the query, the records will increase from ca 15k rows to over 100k rows in both queries.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: Inventory Update - Updated rows from one table to another & add rows for new orders

    In this code
    Please Login or Register  to view this content.
    It appears that you are inserting data from the OrderReport and then reinserting from the InventoryReportRaw if I am not mistaken. I think that you do not want the second FROM reference. Look at this SQL tutorial on syntax for this type of statement

    http://www.w3schools.com/sql/sql_insert_into_select.asp

    The FROM portion of the statement only references the source table.

  5. #5
    Registered User
    Join Date
    07-01-2013
    Location
    Berlin
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Inventory Update - Updated rows from one table to another & add rows for new orders

    Hi Alan,

    thank you so much! This worked like a charm!

    Do you, or anyone else, have any insights into the Update query?
    UPDATE OrderReport RIGHT JOIN InventoryReportRaw ON OrderReport.EndUserNr = InventoryReportRaw.[Mobile Number] SET InventoryReportRaw.[Last Name] = [OrderReport].[EndUserLastName], InventoryReportRaw.[First Name] = [OrderReport].[EndUserFirstName], InventoryReportRaw.Email = [OrderReport].[EndUserEmail], InventoryReportRaw.Tariff = [OrderReport].[Tariff], InventoryReportRaw.[Contract end date] = [OrderReport].[closure date], InventoryReportRaw.[Contract end date] = [OrderReport].[closure date]
    WHERE (((OrderReport.TransactionType)="Svc-chg-details" Or (OrderReport.TransactionType)="Svc-chg-details" Or (OrderReport.TransactionType)="Svc-chg-details" Or (OrderReport.TransactionType)="Svc-Chg-Tariff" Or (OrderReport.TransactionType)="Terminate-Nr" Or (OrderReport.TransactionType)="CTN-TransferOut") AND ((OrderReport.Status)="Completed"));

    Thanks,

    Roman

  6. #6
    Registered User
    Join Date
    07-01-2013
    Location
    Berlin
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Inventory Update - Updated rows from one table to another & add rows for new orders

    Hi,

    I have just played around and fixed it. The new code now is:

    UPDATE OrderReport RIGHT JOIN InventoryReportRaw ON OrderReport.EndUserMSISDN = InventoryReportRaw.[Mobile Number] SET InventoryReportRaw.[Last Name] = [OrderReport].[EndUserLastName], InventoryReportRaw.[First Name] = [OrderReport].[EndUserFirstName], InventoryReportRaw.Email = [OrderReport].[EndUserEmail], InventoryReportRaw.Tariff = [OrderReport].[Tariff], InventoryReportRaw.[Contract end date] = ""
    WHERE (((OrderReport.TransactionType)="Svc-chg-details") AND ((OrderReport.Status)="Completed")) OR (((OrderReport.TransactionType)="Svc-Chg-Tariff") AND ((OrderReport.Status)="Completed"));

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I would like to append and update excel master workbook with new and updated rows.
    By uvwaves in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-24-2013, 03:14 PM
  2. Update a table but only few rows
    By c.vaibhav in forum Excel General
    Replies: 0
    Last Post: 06-28-2011, 07:01 AM
  3. Automatically Update Rows in Table
    By komgol in forum Excel General
    Replies: 1
    Last Post: 06-08-2010, 05:30 PM
  4. Replies: 2
    Last Post: 11-03-2009, 03:30 PM
  5. Display and Print Orders' First Rows
    By cevatyildiz in forum Excel General
    Replies: 4
    Last Post: 02-11-2009, 09:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1