Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Temp table

Status
Not open for further replies.

hlybbi

Programmer
Mar 19, 2003
91
IS
how can i read from one table and set the records to a temp table

i was going to select values from 2 tables and add to one temp table and then read the temp table

how can i do this

Best regards Hlynur
 
Are both of the tables you are select from have the same field definitions and sizes?

Thanks

J. Kusch
 
If the number of fields in your source tables are the same as your target temp table ... you would run
Code:
INSERT INTO #TempTable 
  SELECT * FROM Table1

INSERT INTO #TempTable 
  SELECT * FROM Table2

If there are specific fields in your source table you need to import into the target temp table ... you would run
Code:
INSERT INTO #TempTable
  SELECT Field1, Field2, Field3 ... FROM Table1

INSERT INTO #TempTable
  SELECT Field1, Field2, Field3 ... FROM Table2

Thanks

J. Kusch
 
hlybbi,

If the number of fields in your source tables are the same as your target temp table why do you need a temp table why don't you just use a union

select * from table1
union
select * from table2

I would use only temp tables if i'm manipulating data

Martyc71
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top