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
 insert into

Author  Topic 

notsosuper
Posting Yak Master

190 Posts

Posted - 2005-09-13 : 13:49:35
I have query that gets data from three different table, I want to create a table called Test that it should contain result from that query, how can I do that?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-09-13 : 13:53:33
put the INTO clause after the SELECT and befor the FROM clauses

select...
INTO Test
from...

EDIT:
the above "creates" the table for you. If you already have the table existing, then use "INSERT":

INSERT Test (<colList>)
SELECT <colList>
FROM...

Be One with the Optimizer
TG
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-09-13 : 13:54:07
SELECT t1.Column, ...
INTO Test
FROM Table1 t1
INNER JOIN Table2 t2
ON t1.Column1 = t2.Column1
INNER JOIN Table3 t3
ON t2.Column2 = t3.Column2
WHERE...

Tara
Go to Top of Page

notsosuper
Posting Yak Master

190 Posts

Posted - 2005-09-13 : 14:06:35
how about if second table needs subselect, how can I replace that in to code?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-09-13 : 14:08:42
It doesn't matter what it needs. All you need to do is add the INTO part between the SELECT and the FROM. Check SELECT INTO in SQL Server Books Online for details.

Tara
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-09-13 : 15:12:04
Look at the hint link below to get an answer fast to your question

Or are you still formulating a question?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-14 : 01:45:13
>>how about if second table needs subselect, how can I replace that in to code?

Select * into NewTable from (your_other_query) T

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-09-14 : 12:25:37
quote:
Originally posted by madhivanan

>>how about if second table needs subselect, how can I replace that in to code?

Select * into NewTable from (your_other_query) T

Madhivanan

Failing to plan is Planning to fail



That just isn't needed for this. Take your entire query and just insert "INTO NewTable" between the SELECT portion and the FROM portion. That's it.

Tara
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-15 : 00:28:29
Thanks Tara for the clarification

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -