Updating one table from another

  • Now i am having a problem i hope one of you can help me with. I am trying to update a table named OrderDetails having the field name of PDate. Update is supposed to come from a table named PartsPricing field name of PDate. this is what i came up with so far but i keep getting an error of:

    Msg 4104, Level 16, State 1, Line 1

    The multi-part identifier "dbo.PartsPricing.PartID" could not be bound.

    Any help would be appreciated. Here is th statement i am running as a query.

    UPDATE OrderDetails

    SET OrderDetails.PDate = (SELECT PartsPricing.PDate

    FROM PartsPricing

    WHERE OrderDetails.PartID = PartsPricing.PartID)

    WHERE EXISTS

    (SELECT OrderDetails.PartID

    FROM OrderDetails

    WHERE OrderDetails.PartID = PartsPricing.PartID)

  • Hi,

    You can try this as well:

    UPDATE A

    SET A.PDate = B.PDate

    FROM OrderDetails A INNER JOIN PartsPricing B on

    (A.PartID = B.PartID)

    Warm Regards,
    Neel aka Vijay.

  • Thank you for your Response!

    I followed your advice and i receive another error

    Msg 208, Level 16, State 1, Line 10

    Invalid object name 'OrderDetails'.

    Thanks for your help!

  • HI,

    Make sure you are connected to the correct database and that the table name is correct.

    That is basically saying that it can't find your OrderDetails table!

    Thanks

    Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • Make sure you give a fully qualified name for the table.. something like:

    [databasename].[dbo].OrderDetails

    Warm Regards,
    Neel aka Vijay.

  • Yeah i figuired it out i think the query is running right now. I had to put the servername.DBname.Schema.TableName in the statment.

    Thank you very much for your help and advice!

  • Is there away to get around typing the servername.DBname.Schema in a statement like that?

  • You can consider using a Synonym. For more info:

    http://msdn.microsoft.com/en-us/library/ms177544.aspx

    Warm Regards,
    Neel aka Vijay.

  • Thanks!

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply