none
How to move from one SQL Server table to another

    Question

  • Suppose I have two tables:

    Employee1:

    EmpName varchar(100)

    EmpAddress varchar(200)

    And

    Employee2:

    EmpID int,

    EmpName varchar(100),

    EmpAddress varchar(200)

    Note: EmpID is not an identity field

    How to move all the data from Employee1 table to Employee2 table with values of EmpID as 1, 2, 3, ....so on.

    Can anyone have any idea?

    Friday, August 29, 2014 9:06 AM

Answers

  • INSERT INTO [Employee2] (EmpID, EmpName, EmpAddress)  
    SELECT ROW_NUMBER() OVER (ORDER BY EmpName), EmpName, EmpAddress from Employee1
    

    should work
    • Proposed as answer by Valentino VrankenMVP Friday, August 29, 2014 10:43 AM
    • Marked as answer by iamanujit Wednesday, September 03, 2014 8:14 AM
    Friday, August 29, 2014 10:11 AM

All replies