Best way to move data between tables

Last post 10-07-2008, 12:23 PM by cbehm. 4 replies.
Sort Posts: Previous Next
  •  08-27-2008, 11:17 AM Post number 69299

    Best way to move data between tables

    Hi,

    Any and all help greatly appreciated!! :)

    I've got two tables where I want to take data out of table1.columnA and place it into table2.columnB. The caveat to this is that table 2 already contains data and I want the column to be added where existing data sits linked by an ID column.

    What would be the best way to achieve this in SQL Server?

    Thanks,

    Mosser212

  •  09-03-2008, 2:47 AM Post number 69365 in reply to post number 69299

    Re: Best way to move data between tables

    The insert into statment will do what you need.

  •  09-03-2008, 3:48 PM Post number 69391 in reply to post number 69365

    Re: Best way to move data between tables

    the UPDATE...FROM statement might give you more results. The syntax is a bit puzzling and I'm never quite sure if it will work, but it generally seems to.
  •  09-08-2008, 11:02 AM Post number 69451 in reply to post number 69299

    • randyvol is not online. Last active: 11-12-2008, 4:06 PM randyvol
    • Top 25 Contributor
    • Joined on 04-04-2007
    • Columbia, SC (USA)
    • Level 2: Deep Blue

    Re: Best way to move data between tables

    I'm having a little trouble figuring out exactly what your tables would appear to be, but as I understand you, table1 has data in column a that you want to move to table2 column b and it sounds to me like a column 'ID' is the relationship between the two?

    If that is the case, using Phil's suggestion, it would be someting like

    update table2

    set B = table1.A

    from table2

    inner join table1

    on table1.ID = table2.ID

     

    If I have misunderstood you, apologies.

  •  10-07-2008, 12:23 PM Post number 69942 in reply to post number 69299

    • cbehm is not online. Last active: 10-07-2008, 12:23 PM cbehm
    • Top 150 Contributor
    • Joined on 03-06-2008
    • Level 1: Deep thought

    Re: Best way to move data between tables

    here is the code that works  your colum names would differ

     

     

    INSERT INTO dbo.mapentity (oldentityid) SELECT scode FROM dbo.property

View as RSS news feed in XML