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
 General SQL Server Forums
 New to SQL Server Programming
 select statement for insert

Author  Topic 

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-04-29 : 14:06:23
i am selecting and need to insert into another table

select top 100 * from table 1

I then want to take the result and insert the records into another table.

is there a way to do the insert statement and select statement in one?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-29 : 14:08:34
insert into yourtable (column1, ...)
select column1, ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-04-29 : 14:12:49
[code]
INSERT INTO TargetTable (Col1, Col2, ...)
SELECT ColA, ColB, ...
FROM Table1
WHERE ...
[/code]
if you want to take the results from that into a THIRD insert/update/etc then you nee d to use the OUTPUT statement as well
Go to Top of Page

CrazyT
Yak Posting Veteran

73 Posts

Posted - 2010-04-29 : 14:16:22
thanks -- after posting i thought about it
Go to Top of Page
   

- Advertisement -