July 20, 2010 at 11:45 pm
Hi all
Can some one please tell me if i can use a select into in a From Clause Sub Query or a Insert into in the From clause query.
I have a complex query with From Clause Queries in it using a Union all..
I am trying to insert it into a table can you please let me know if this is possible and if so how
thanks in advance
Vani
E.g.
Select A, B, C from (Select A1, B1, C1 from (Select A2, B2, C2 from Table1 Union Select E2, F2, G2 from Table1)
and rest of the code
Sorry about the complex e.g.
July 21, 2010 at 6:28 am
The INTO clause goes before the first FROM:
Select A, B, C
into YourNewTable
from (Select A1, B1, C1 from (Select A2, B2, C2 from Table1 Union Select E2, F2, G2 from Table1)
Your question sounds like you're trying to select into the new table from the subquery. If you think about this for a moment, you'll realize why this can't be done... if you insert into a new table, the subquery won't be returning any data to the query calling the subquery. If that is what you really want, you'll need to break it out into separate statements:
Select A1, B1, C1
INTO YourNewTable
from (Select A2, B2, C2 from Table1 Union Select E2, F2, G2 from Table1)
Select A, B, C from YourNewTable
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
July 25, 2010 at 11:37 pm
Hi Wayne
Thanks for ur help... I got it now
Cheers for your help 🙂 🙂
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply