Need help merging 2 tables into 1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djl531
    New Member
    • Jan 2008
    • 2

    #1

    Need help merging 2 tables into 1

    SQL 2005 database. What I have is a database with user info in it. It is a list of names, dob, drivers license numbers, etc. I have an update that i need to merge into it. So I have an identical db with a subset of records that are only changes. The only common field are the DL numbers. Names change when you get married, expiration dates change when a DL is renewed and we get new drivers all the time with new DL numbers. Here's the code:

    use [DPSMV-BE]
    UPDATE "ladps20070 615"
    SET
    dbo.ladps200706 15.SSN = dbo.DL06152007. SSN,
    dbo.ladps200706 15.LADL = dbo.DL06152007. LADL,
    dbo.ladps200706 15.Class = dbo.DL06152007. Class,
    dbo.ladps200706 15.ExpDate = dbo.DL06152007. ExpDate,
    dbo.ladps200706 15.DOB = dbo.DL06152007. DOB,
    dbo.ladps200706 15.Name = dbo.DL06152007. Name
    WHERE ladps20070615.L ADL = DL06152007.LADL


    I am updating the database that is the original we started with. I want to replace the 6 columns with data from the DL06152007 table based on a match of the LADL number, hence the Where clause. These are the only columns in the database. So it is an all or nothing replace.

    This is the error I get:
    Msg 4104, Level 16, State 1, Line 2
    The multi-part identifier "DL06152007.LAD L" could not be bound.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by djl531
    SQL 2005 database. What I have is a database with user info in it. It is a list of names, dob, drivers license numbers, etc. I have an update that i need to merge into it. So I have an identical db with a subset of records that are only changes. The only common field are the DL numbers. Names change when you get married, expiration dates change when a DL is renewed and we get new drivers all the time with new DL numbers. Here's the code:

    use [DPSMV-BE]
    UPDATE "ladps20070 615"
    SET
    dbo.ladps200706 15.SSN = dbo.DL06152007. SSN,
    dbo.ladps200706 15.LADL = dbo.DL06152007. LADL,
    dbo.ladps200706 15.Class = dbo.DL06152007. Class,
    dbo.ladps200706 15.ExpDate = dbo.DL06152007. ExpDate,
    dbo.ladps200706 15.DOB = dbo.DL06152007. DOB,
    dbo.ladps200706 15.Name = dbo.DL06152007. Name
    WHERE ladps20070615.L ADL = DL06152007.LADL


    I am updating the database that is the original we started with. I want to replace the 6 columns with data from the DL06152007 table based on a match of the LADL number, hence the Where clause. These are the only columns in the database. So it is an all or nothing replace.

    This is the error I get:
    Msg 4104, Level 16, State 1, Line 2
    The multi-part identifier "DL06152007.LAD L" could not be bound.
    check your syntax

    try doing something like...

    UPDATE ThisTable
    set ThisTable.ThisC olumn = FromThisTable.T hisColumn,
    ThisTable.Other Column = FromThisTable.O therColumn
    from FromThisTable
    where ThisTable.Key = FromThisTable.K ey


    -- ck

    Comment

    Working...