select *from table1
union all
select *from table2
)
into #temp3....................这样的语句应该怎么写
也就是说如何把union 得到的结果放到临时表中去
7 个解决方案
#1
select * into # from table1
union all
select *from table2
union all
select *from table2
#2
select * into # from (
select *from table1
union all
select *from table2
) t
#3
CREATE TABLE #A (ID INT, AMT INT, S_DATE VARCHAR(10))
INSERT #A
SELECT 1, 3000, '2008-11-21' UNION ALL
SELECT 1, 5000, '2008-11-19' UNION ALL
SELECT 2, 4000, '2008-11-17' UNION ALL
SELECT 2, 6000, '2008-11-19' UNION ALL
SELECT 3, 1000, '2008-10-12' UNION ALL
SELECT 3, 200, '2008-11-02'
CREATE TABLE #B (ID INT, AMT INT, S_DATE VARCHAR(10))
INSERT #B
SELECT 1, 3000, '2008-11-21' UNION ALL
SELECT 1, 5000, '2008-11-19' UNION ALL
SELECT 2, 4000, '2008-11-17' UNION ALL
SELECT 2, 6000, '2008-11-19' UNION ALL
SELECT 3, 1000, '2008-10-12' UNION ALL
SELECT 3, 200, '2008-11-02'
SELECT * INTO #C FROM
(SELECT * FROM #A
UNION ALL
SELECT * FROM #B)A
SELECT * FROM #C
DROP TABLE #A,#B
/**
ID AMT S_DATE
----------- ----------- ----------
1 3000 2008-11-21
1 5000 2008-11-19
2 4000 2008-11-17
2 6000 2008-11-19
3 1000 2008-10-12
3 200 2008-11-02
1 3000 2008-11-21
1 5000 2008-11-19
2 4000 2008-11-17
2 6000 2008-11-19
3 1000 2008-10-12
3 200 2008-11-02
#4
select * into #temp3
from table1
union all
select * from table2
)
#5
帮顶
#6
select * into # from (
select *from table1
union all
select *from table2
) t
------------------------------------
正解
select *from table1
union all
select *from table2
) t
------------------------------------
正解
#7
+1
#1
select * into # from table1
union all
select *from table2
union all
select *from table2
#2
select * into # from (
select *from table1
union all
select *from table2
) t
#3
CREATE TABLE #A (ID INT, AMT INT, S_DATE VARCHAR(10))
INSERT #A
SELECT 1, 3000, '2008-11-21' UNION ALL
SELECT 1, 5000, '2008-11-19' UNION ALL
SELECT 2, 4000, '2008-11-17' UNION ALL
SELECT 2, 6000, '2008-11-19' UNION ALL
SELECT 3, 1000, '2008-10-12' UNION ALL
SELECT 3, 200, '2008-11-02'
CREATE TABLE #B (ID INT, AMT INT, S_DATE VARCHAR(10))
INSERT #B
SELECT 1, 3000, '2008-11-21' UNION ALL
SELECT 1, 5000, '2008-11-19' UNION ALL
SELECT 2, 4000, '2008-11-17' UNION ALL
SELECT 2, 6000, '2008-11-19' UNION ALL
SELECT 3, 1000, '2008-10-12' UNION ALL
SELECT 3, 200, '2008-11-02'
SELECT * INTO #C FROM
(SELECT * FROM #A
UNION ALL
SELECT * FROM #B)A
SELECT * FROM #C
DROP TABLE #A,#B
/**
ID AMT S_DATE
----------- ----------- ----------
1 3000 2008-11-21
1 5000 2008-11-19
2 4000 2008-11-17
2 6000 2008-11-19
3 1000 2008-10-12
3 200 2008-11-02
1 3000 2008-11-21
1 5000 2008-11-19
2 4000 2008-11-17
2 6000 2008-11-19
3 1000 2008-10-12
3 200 2008-11-02
#4
select * into #temp3
from table1
union all
select * from table2
)
#5
帮顶
#6
select * into # from (
select *from table1
union all
select *from table2
) t
------------------------------------
正解
select *from table1
union all
select *from table2
) t
------------------------------------
正解
#7
+1