Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 insert

Author  Topic 

shobha
Starting Member

1 Post

Posted - 2002-06-17 : 17:09:21
What would be the sql query if I want to insert some fields in a new table from 5 different tables. These 5 tables have one common field (nycuid). I used following query but getting error.

insert into collectall
select nycuid, nycName, nycAddress, nycDunsNumber
union
select associd, assocName, assocAddress, assocDunsNumber
union
select duid, duName, duAddress, duDuns
union
select guid, guName, guAddress, guDuns
union
select hpid, hpName, hpAddress, hpDuns

from nysCompany, assocCompany1, duCompany1, guCompany1, hpCompany1
where
nysCompany.nycuid=assocCompany1.nycuid and
nysCompany.nycuid=DuCompany1.nycuid and
nysCompany.nycuid=guCompany1.nycuid and
nysCompany.nycuid=hpCompany1.nycuid



Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-06-17 : 18:49:22
You need to go back and look up UNION in Books Online; you're syntax is wrong. The UNION operator combines the results of two or more queries into a single rowset. Once you sort out the UNION, your insert should work (assuming the columns in your table match the rowset: it is best practice to explicitly name the columns in an insert statement.)

<O>
Go to Top of Page
   

- Advertisement -