need help with update query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #16
    Try this:

    SELECT Inventory.Inven toryID, Workorders.Sale sID
    FROM (Inventory INNER JOIN Workorders
    ON Inventory.Inven toryID = Workorders.Sale sID)
    WHERE (Inventory.Inve ntoryID=[Forms]![First empty InventoryID]![InventoryID]);



    Originally posted by arion
    Yes, now it was working. But it is showing me 20,000 records instead of 100. It is repeating the workorders. And the inventoryID was the first empty one, but it didn't go on. It uses the same InventoryID for all 20,000 records.

    Comment

    • arion
      New Member
      • Oct 2006
      • 23

      #17
      It is then not showing any record. When I delete the joint property it is showing me every workorder but still with the same first empty inventoryID.

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #18
        Ok Arion back to basics

        In your Inventory table you have a primary key called InventoryID, Yes?

        In your Workorders table you have a key called Sales ID which is based on InventoryID, Yes/No?

        If No, then what is the relationship between the two tables.


        Originally posted by arion
        It is then not showing any record. When I delete the joint property it is showing me every workorder but still with the same first empty inventoryID.

        Comment

        • arion
          New Member
          • Oct 2006
          • 23

          #19
          Yes, the primary key for Inventory is InventoryID, but the primary key for Workorders is WorkorderNumber , not salesID.

          When I build the joint property between inventory.worko rdernumber and workorders.work ordernumber it is not showing any record either.

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #20
            Originally posted by arion

            When I build the joint property between inventory.worko rdernumber and workorders.work ordernumber it is not showing any record either.
            To join two tables you must have a one to many relationship. This means that one of the tables has a field (doesn't have to be primary key but it usually is) or a combination of fields??? that are unique to that table.

            The field or fields would have to be represented in the other table. Although you can preform this join through a series of tables the condition must be true for each. Does this make sense. If you post the structure of your tables and tell me how they relate I will see if I can help. Make sure the date types of the relationships are the same.

            Comment

            • arion
              New Member
              • Oct 2006
              • 23

              #21
              The inventory table is related to the workorders table through workorderNumber , the table workorders and SQ customers and sales are realted to each other through salesID.

              I don't know how to relate the WorkordersNewVa lve table to these tables. This table shows the WOIndex which is included in the workordernumber . WorkorderNumber is built from salesID+WOIndex . Is that what you mean?

              Comment

              • MMcCarthy
                Recognized Expert MVP
                • Aug 2006
                • 14387

                #22
                Originally posted by arion

                WorkorderNumber is built from salesID+WOIndex
                Can I get examples of the structure and content of both these fields.

                Comment

                • arion
                  New Member
                  • Oct 2006
                  • 23

                  #23
                  The WorkorderNewVal ve table consists of the following fields:

                  Field Name Data Type
                  WOIndex Number
                  Part Text
                  Abbreviation Text
                  Material Text
                  Quantity Number

                  WOIndex content is the numbers 1 through 100. Part is e.g. Sideplate and the Abbreviation could be Sp.

                  The Workorders table consists of the fields:

                  Field Name Data Type
                  WorkorderNumber Number
                  SalesID Number
                  Quantity Number
                  Material Text

                  For the sale with salesID 3456 the workorderNumber s would then be 345601 through 3456100.

                  The Inventory table has the fields

                  InventoryID Number
                  WorkorderNumber Number
                  Quantity Number
                  Distinguishing Mark Text
                  etc.

                  The inventoryID already exists and the Distinguishing mark field is telling if the inventoryID is empty or not.

                  The problem that I have is that it is recognizing the first empty InventoyID but is not updateting with all 100 records. It is just showing me the record for workorderNumber 345699. Do you need more information?

                  I am going offline soon and will continue on monday. I thank you for your help, I really appreciate that.

                  Comment

                  • MMcCarthy
                    Recognized Expert MVP
                    • Aug 2006
                    • 14387

                    #24
                    Workorders

                    Field Type
                    WorkorderNumber Number (PK)
                    SalesID Number
                    Quantity Number
                    Material Text

                    For the sale with salesID 3456 the workorderNumber s would then be 345601 through 3456100.

                    Inventory

                    Field Type
                    InventoryID Number (PK)
                    WorkorderNumber Number (FK to WorkOrders)
                    Quantity Number
                    Distinguishing Mark Text
                    etc.


                    The inventoryID already exists and the Distinguishing mark field is telling if the inventoryID is empty or not.

                    The problem that I have is that it is recognizing the first empty InventoyID but is not updateting with all 100 records. It is just showing me the record for workorderNumber 345699. Do you need more information?
                    Are you trying to do an update or an append (insert) query?

                    Are you trying to add workorders to the Inventory table?

                    Comment

                    • arion
                      New Member
                      • Oct 2006
                      • 23

                      #25
                      If I would use an append query it would create new InventoryIDs, right?

                      I thought I need to use an update query because the inventoryIDs already exist. The query should just fill out the empty fields, for example "WorkorderNumbe r", "Quantity" etc., for existing InventoryIDs.

                      Comment

                      • MMcCarthy
                        Recognized Expert MVP
                        • Aug 2006
                        • 14387

                        #26
                        The problem is you are trying to update a table that has no relationship to the table you are updating from or any other table.

                        Try the following:

                        UPDATE Inventory SET ([Drawing#], WorkorderNumber , Material, Remarks, [Distinguishing Mark])=(SELECT Left([Model#],5) & [Abbreviation], [SalesID] & [WOIndex], Material, Remarks, 'Changed' FROM WorkOrders WHERE WorkOrders.Sale sID=[Forms]![Sales Form].[SalesID]) WHERE WorkorderNumber Is Null;


                        omit the following you can do them later:
                        Inventory.Descr iption = [WorkorderNewVal ve].[part],
                        Inventory.Quant ity = [WorkorderNewVal ve].[Quantity],

                        Comment

                        • arion
                          New Member
                          • Oct 2006
                          • 23

                          #27
                          When I try to do the following, it is saying "Syntax error in Update statement".

                          UPDATE Inventory SET ([Drawing#], WorkorderNumber , Material, Remarks, [Distinguishing Mark])=(SELECT Left([Model#],5) & [Abbreviation], [SalesID] & [WOIndex], Material, Remarks, 'Changed' FROM WorkOrders WHERE WorkOrders.Sale sID=[Forms]![Sales Form].[SalesID]) WHERE WorkorderNumber Is Null;

                          Comment

                          • MMcCarthy
                            Recognized Expert MVP
                            • Aug 2006
                            • 14387

                            #28
                            I just don't think it can be done. I'd a feeling the last one wouldn't work but thought it was worth a try.

                            Why are you adding the InventoryNo first it would be so much easier to do this as an insert query.

                            Comment

                            • arion
                              New Member
                              • Oct 2006
                              • 23

                              #29
                              The problem is that we are having one main database and some satellite databases. Every person is working with his or her own database and the data will be imported to the main database. If I use auto number for InventoryID there will be some dublicates or some entries will just be overwritten. That is the reason why I thought we need to give each satellite its own inventoryIDs and use an update query. Do you see any other opportunity how to do the exchange?

                              Comment

                              • MMcCarthy
                                Recognized Expert MVP
                                • Aug 2006
                                • 14387

                                #30
                                The only other way to do this is using recordsets in vba code. Leave it with me.

                                Comment

                                Working...