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!

Write to a temporary table 3

Status
Not open for further replies.

Michael57

Technical User
Nov 15, 2005
131
CA
I was told you can write the output of a query to a temporary table to be use again with some other query.
How can this be done.
 
id is a (and the only) column name in the temp table you create.

id is of a data type integer.

[monkey][snake] <.
 
id is the column name
int is the data type

you can name them whatever you want
example


Code:
create table #bla (id int,SomeName varchar(666), SomeValue decimal(12,3))
insert #bla values(1,'SQL',12.555)
insert #bla values(2,'SQL2',12.23)
insert #bla values(3,'SQL3',2424242.555)
select * from #bla


Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
michael, go look up the create table command.

Also, use query analyzer or management studio to script some already existing tables... you'll see the DDL (data definition language) for how to define existing tables.

This is such a basic question that you've asked, that you need to read some books and already existing resources instead of asking us here in this forum these questions. You'll save our time and yours by doing that.

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
how would it look if I had more than one column?
(id int, id2 int)
 
You can also skip defining the table:

Select Field1,Field2,Field3
into #TempTable
from SourceTable

And take them from the source table if you don't need a key/identity.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top