Quantcast
Viewing all articles
Browse latest Browse all 4871

combining multiple tables into one

First, the four tables are of the same schema. They are titled xyzfirms20171,  xyzfirms20172, and so on. They are just quarterly editions of the same table. I did not create the originals but now am tasked with combining them into one unit so that the queries do not involve 4 quarters/tables. 

My first idea is to create table and then write a insert into script for each of the four quarters. My questions is if there is a better way. This seems like the long way to do it. 

Text
create table xyzfirmstotal
(
field1  char(2)
.
.
.
);

Insert into dbo.xyzfirmstotal (fields 1-29)
select
fields 1-29
from dbo.xyzfirms20171
union all
Insert into dbo.xyzfirmstotal (fields 1-29)
select
fields 1-29
from dbo.xyzfirms20172
union all
....
and so on. 

Viewing all articles
Browse latest Browse all 4871

Trending Articles