Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Posts
    1

    Unanswered: Beginner question about insert into table

    Hello to all,

    I'm learning MS SQL server (and SQL programming in general).

    I have the following problem.

    I have Table 1 (T1) and it has 3 columns. This table is filled with data.
    I have table 2 (T2) which has 4 columns.
    I want to copy data from T1 to T2 while 4th should be NULL.
    I have tried to execute something like this but no success:

    insert into T2 (T2.col1, T2.col2, T2.col3) values(select * from T1)

    Can you explain me how to solve this.

    My wish is that after executing SQL query, three columns of T2 is filled with data from T1 while 4th column is NULL.


    Thank you

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    the correct syntax is as follows:
    Code:
    INSERT 
      INTO T2 (col1, col2, col3) 
    SELECT * 
      FROM T1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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