If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Beginner question about insert into table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-12-11, 16:17
Askaletto Askaletto is offline
Registered User
 
Join Date: Dec 2011
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 12-12-11, 16:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
the correct syntax is as follows:
Code:
INSERT 
  INTO T2 (col1, col2, col3) 
SELECT * 
  FROM T1
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On