copy data from one table to the next with dufferent columns positions
Results 1 to 2 of 2

Thread: copy data from one table to the next with dufferent columns positions

  1. #1
    Join Date
    Jul 2014
    Posts
    8

    copy data from one table to the next with dufferent columns positions

    I am trying to change a database from excel to mssql. After importing to MSSQL

    The problem the columns heading are in different positions for example one year it is
    IDNumber, First_Name, Last_Name and the following year it maybe
    last_Name, First_Name, IDnumber.

    I tried using

    INSERT INTO TABLE2 SELECT * FROM TABLE1

    but I am getting

    Msg 213, Level 16, State 1, Line 1
    Column name or number of supplied values does not match table definition.

    My question is must the columns heading be in the same order to copy data from one table to the next

  2. #2
    Join Date
    Sep 2002
    Posts
    5,900
    You can list column names in the statement like following as long as you put in same number of columns:
    insert into table2 (col1, col2, ...) select col3, col4, ... from table1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •