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 > Data Access, Manipulation & Batch Languages > ANSI SQL > insert statement help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-14-03, 11:51
pd29 pd29 is offline
Registered User
 
Join Date: Dec 2003
Posts: 1
insert statement help

hi,
i have a small question regarding sql, there are two tables that i need to work with on this, one has fields like:
Table1:
(id, name, street, city, zip, phone, fax, etc...) about 20 more columns
Table2:
name
what i need help with is that table2 contains about 200 distinct names that i need to insert into table1, i'm using sql server, is there a way to insert them into table1?? i'm not sure how to write a query within the insert statment to get them inserted into table1? something like:
insert into table(id, name, street, zip, phone, fax, ...) values(newid(), (select distinct name from table2), null, null, null....)
and is there a way to do it without all the nulls having to be put in, there are about 20 more columns in table1, and id in table1 is unique.
Reply With Quote
  #2 (permalink)  
Old 12-14-03, 12:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
insert into table1 ( name)
select distinct name from table2


rudy
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