Need an Insert SQL Script

  • Dear All,

    Am a newbie at this SQL stuff.  Essentially, what I want to do, insert data into a column of a table - Contacts.WebUserID from a table in another database.  Thus the databases are different.  The table/column from the other database is called Users.ID and in both tables there are columns that can be joined as they contain the same data Contacts.ContactID and Users.ContactIDAlias.

    Can seem to get the script to work.

    Help.


    TheKutts

  • UPDATE contacts INNER JOIN contacts ON users.contactidalias = contacts.contactid SET contacts.webuserid=users.id

    MVDBA

  • You need to use a three-part name to refer to a table in another database: <database>.<schema>.<table>.  If the table is owned by dbo the middle part can be empty.

    update c set WebUserID = u.ID

    from Contacts c

    inner join OtherDB..Users u ON c.ContactID = u.ContactIDAlias

Viewing 3 posts - 1 through 2 (of 2 total)

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