| 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 clausesselect...INTO Testfrom...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 OptimizerTG |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-09-13 : 13:54:07
|
| SELECT t1.Column, ...INTO TestFROM Table1 t1INNER JOIN Table2 t2ON t1.Column1 = t2.Column1INNER JOIN Table3 t3ON t2.Column2 = t3.Column2WHERE...Tara |
 |
|
|
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? |
 |
|
|
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 |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
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) TMadhivananFailing to plan is Planning to fail |
 |
|
|
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) TMadhivananFailing 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 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-15 : 00:28:29
|
| Thanks Tara for the clarificationMadhivananFailing to plan is Planning to fail |
 |
|
|
|