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

    Unanswered: 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.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    insert into table1 ( name)
    select distinct name from table2


    rudy

Posting Permissions

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