select ColumnNameA from Table1 union all select ColumnNameA from Table2还是 insert into Table1 select ColumnNameA from table2
楼上的已经很清楚了。如果再想完整点,加上case 判断一下后再Union
第一个select 各列都用convert()来指定类型
--> 测试数据: @tablea declare @tablea table (id int,col varchar(4)) insert into @tablea select 1,'a' union all select 2,'b' union all select 3,'c'select * from @tablea --> 测试数据: @tableb declare @tableb table (id int,col varchar(4)) insert into @tableb select 4,null union all select 5,null union all select 6,nullselect * from @tableb select * from @tablea union all select * from @tableb/*直接合并就行,没有影响呀? id col ----------- ---- 1 a 2 b 3 c 4 NULL 5 NULL 6 NULL */
union all
select ColumnNameA from Table2还是
insert into Table1 select ColumnNameA from table2
--> 测试数据: @tablea
declare @tablea table (id int,col varchar(4))
insert into @tablea
select 1,'a' union all
select 2,'b' union all
select 3,'c'select * from @tablea
--> 测试数据: @tableb
declare @tableb table (id int,col varchar(4))
insert into @tableb
select 4,null union all
select 5,null union all
select 6,nullselect * from @tableb
select * from @tablea
union all
select * from @tableb/*直接合并就行,没有影响呀?
id col
----------- ----
1 a
2 b
3 c
4 NULL
5 NULL
6 NULL
*/
看样子不是这样合并?