Select Into and using UNION statement 
Author Message
 Select Into and using UNION statement
Is it possible to to a Select Into using a Union statement?  For example:

Select Into #TempTable
 0 as Field1,
 0 as Field2,
 0 as Field3

Union

Select Into #TempTable
 1 as Field1,
 1 as Field2,
 1 as Field3

Union

Select Into #TempTable
 2 as Field1,
 2 as Field2,
 2 as Field3

J.R.
Largo SQL Tools
The Finest Collection of SQL Tools Available
http://www.***.com/



Sat, 18 Mar 2006 13:24:55 GMT
 Select Into and using UNION statement

Try:

Select * Into #TempTable
from
(select col1,col2 from tab1
 union all
 select col1,col2 from tab2) a

- Vishal

Quote:
>-----Original Message-----
>Is it possible to to a Select Into using a Union

statement?  For example:
Quote:

>Select Into #TempTable
> 0 as Field1,
> 0 as Field2,
> 0 as Field3

>Union

>Select Into #TempTable
> 1 as Field1,
> 1 as Field2,
> 1 as Field3

>Union

>Select Into #TempTable
> 2 as Field1,
> 2 as Field2,
> 2 as Field3

>J.R.
>Largo SQL Tools
>The Finest Collection of SQL Tools Available
>http://www.largosqltools.com

>.



Sat, 18 Mar 2006 13:37:10 GMT
 Select Into and using UNION statement
Or even shorter (but perhaps not as readable):

SELECT au_lname , au_fname
 INTO #tmp2
 FROM authors
UNION ALL
SELECT au_lname, au_fname
 FROM authors

INTO can be specified in the column list of the *first* SELECT statement.

--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as ugroup=microsoft.public.sqlserver


Quote:
> Try:

> Select * Into #TempTable
> from
> (select col1,col2 from tab1
>  union all
>  select col1,col2 from tab2) a

> - Vishal

> >-----Original Message-----
> >Is it possible to to a Select Into using a Union
> statement?  For example:

> >Select Into #TempTable
> > 0 as Field1,
> > 0 as Field2,
> > 0 as Field3

> >Union

> >Select Into #TempTable
> > 1 as Field1,
> > 1 as Field2,
> > 1 as Field3

> >Union

> >Select Into #TempTable
> > 2 as Field1,
> > 2 as Field2,
> > 2 as Field3

> >J.R.
> >Largo SQL Tools
> >The Finest Collection of SQL Tools Available
> >http://www.largosqltools.com

> >.



Sat, 18 Mar 2006 14:23:53 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. USING A FIELD FROM MAIN SELECT STATEMENT IN SUB SELECT STATEMENT

2. Select statement - maybe Union/Join

3. Select statement with UNION

4. bug 55031: Select statements with union may cause error 8618

5. UNION Select statement in SP

6. bug 55031: Select statements with union may cause error 8618

7. Why no union in view select statement?

8. bug 55031: Select statements with union may cause error 8618

9. insert statement using values from a select statement

10. Using Statement.cancel() on a SELECT statement

11. Using IF statements in Select statements

12. Using order by Upper in union statement


 
Powered by phpBB® Forum Software