Monday, March 12, 2012

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.insert into table1 ( name)
select distinct name from table2

rudy

No comments:

Post a Comment