Results 1 to 9 of 9
  1. #1
    dhutton27 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9

    Access2010 update query - need to insert new column (SalesPerID) matching SalesPer

    Hello everyone,



    Having a problem trying to build an update query to insert another column to an existing table. I forgot to add in SalesPerID column(in table OrderDetails) to match SalesPer column. The problem is there are 5,000 lines of orders and I don't want to enter this manually. I have SQL server 2012 and tried to add the column in that way - but would like to know how to do this in Access(or SQL). So I have a table with SalesPerID and would like to query that table to update or append to OrderDetails table. Here is what the table looks like:

    Trying to Build relationships amongst tables so I can use JOINS in my query's - so instead of trashing everything and starting over because I forgot to add Key fields I want to insert the data I need.

    Table:SalesPerson

    SalesPerID already exists on this table
    SalesPerID FirstName LastName Branch SalesPer
    1 Bob Smith Houston BS
    2 Sherry Wiley Boston SW






    Tables: OrderDetails. SalesPerID is the Field or Column that I want to insert - it doesn't exist. Would like to do an update or append query using a JOIN on table SalesPerson. Also see attachment on Database's Relationship diagram - OrderDetails is actually called MO2012to2014 on the attachment....
    OrderID Date Company JobDesc SONUM SalesPer SalesPerID
    1 6/30/14 ACME Drilling 12345 BS 1
    2 7/1/14 Pipe Supply Welding 12356 SW 2
    Attached Thumbnails Attached Thumbnails Relationships1.png  
    Last edited by dhutton27; 07-01-2014 at 09:18 AM. Reason: Format Moved all over the place

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    To the best of my knowledge you can't do it in one step. You need to add the field first, then populate it with an update query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    dhutton27 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9
    Ok, changed the OrderDetails to have the SalesPerID header. Now to do this in design view what arguments are needed to say IF SalesPerson.SalesPer = OrderDetails.SalesPer Then update OrderDetails.SalesID ON Salesperson.SalesPerID.

    (Actually making this a little confusing because OrderDetails table is still called MO2012to1214 and haven't changed it yet) Anyways I can't figure out the correct JOIN syntax in the design view to either use an update, append or make table procedure.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Off the top of my head:

    UPDATE OrderDetails INNER JOIN SalesPerson ON OrderDetails.SalesPer = SalesPerson.SalesPer
    SET OrderDetails.SalesPerID = SalesPerson.SalesPerID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    dhutton27 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9

    Tried an Update Query

    [Tried an make table query and no luck..

    Having a problem trying to build an update query to insert another column to an existing table. I forgot to add in SalesPerID column(in table OrderDetails) to match SalesPer column. The problem is there are 5,000 lines of orders and I don't want to enter this manually. I have SQL server 2012 and tried to add the column in that way - but would like to know how to do this in Access(or SQL). So I have a table with SalesPerID and would like to query that table to update or append to OrderDetails table. Here is what the table looks like:

    Trying to Build relationships amongst tables so I can use JOINS in my query's - so instead of trashing everything and starting over because I forgot to add Key fields I want to insert the data I need.

    Table:SalesPerson

    SalesPerID already exists on this table
    SalesPerID FirstName LastName Branch SalesPer
    1 Bob Smith Houston BS
    2 Sherry Wiley Boston SW






    Tables: OrderDetails. SalesPerID is the Field or Column that I want to insert - it doesn't exist. Would like to do an update or append query using a JOIN on table SalesPerson. Also see attachment on Database's Relationship diagram - OrderDetails is actually called MO2012to2014 on the attachment....
    OrderID Date Company JobDesc SONUM SalesPer SalesPerID
    1 6/30/14 ACME Drilling 12345 BS 1
    2 7/1/14 Pipe Supply Welding 12356 SW 2
    [/QUOTE]

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Is there a new question or are you just restating the original question? If so I'll restate my original answer.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    dhutton27 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9
    I have a new question on the same problem...

    Click image for larger version. 

Name:	OrderDetailsSalesPerson.png 
Views:	6 
Size:	11.9 KB 
ID:	17204

    Here are the two revised tables in question. Where do I insert your solution? in the field list or can I run it from SQL view and if so do I need a SELECT AND FROM statement before your code.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    What I posted was the untested full SQL of an update query. It could be run from SQL view.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    dhutton27 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    9

    Solved - Case Closed

    WOW!! It worked!! Thank You So Much!!!!

    Field List Solution:

    Click image for larger version. 

Name:	FieldListSolution.png 
Views:	5 
Size:	12.6 KB 
ID:	17207


    SQL View Solution:

    UPDATE OrderDetailsTest1 INNER JOIN SalesPersonTest1
    ON OrderDetailsTest1.SalesPer = SalesPersonTest1.SalesPer
    SET OrderDetailsTest1.SalesPerID = SalesPersonTest1.SalesPerID

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

Similar Threads

  1. SQL Update query using data in Excel column
    By tylerg11 in forum SQL Server
    Replies: 2
    Last Post: 09-03-2013, 05:10 PM
  2. Column assignments in an INSERT INTO type of query.
    By tfulmer in forum Import/Export Data
    Replies: 3
    Last Post: 05-01-2013, 01:42 PM
  3. Replies: 3
    Last Post: 09-13-2012, 11:14 AM
  4. Replies: 1
    Last Post: 09-05-2010, 11:28 AM
  5. Replies: 3
    Last Post: 05-19-2010, 10:08 PM

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