insert tab(field) 
select field1 from table where ...
union all select field2 from table where ...
union all select field3 from table where ...
union all select field4 from table where ...

解决方案 »

  1.   

    insert into 表
    select 列1 from(
    select 列1 from 表
    union all
    select 列2 from 表
    union all
    select 列3 from 表
    union all
    select 列4 from 表
    ) a
      

  2.   

    如果要保证顺序的话,需要你的表中有主键.insert into 表
    select 列1 from(
    select 主键,列1 from 表
    union all
    select 主键,列2 from 表
    union all
    select 主键,列3 from 表
    union all
    select 主键,列4 from 表
    ) a order by 主键
      

  3.   

    select id=identity(int,1,1),列1,列2,列3,列4 into #t from 表insert into 新表
    select 列1 from(
    select id,列1 from #t
    union all
    select id,列2 from #t
    union all
    select id,列3 from #t
    union all
    select id,列4 from #t
    ) a order by id
      

  4.   

    insert into 表
    select 列1 from(
    select 列1 from 表
    union all
    select 列2 from 表
    union all
    select 列3 from 表
    union all
    select 列4 from 表
    ) a  --指定一个别名
      

  5.   

    insert 表 (目标列)
    select 列1 from 表
    union all
    select 列2 from 表
    union all
    select 列3 from 表
    union all
    select 列4 from 表
      

  6.   

    insert 表 (目标列)
    select top 1 列1 from 表
    union all
    select top 1 列2 from 表
    union all
    select top 1 列3 from 表
    union all
    select top 1 列4 from 表
      

  7.   

    create table #t(id int,a varchar(10),b varchar(10),c varchar(10),d varchar(10))
    create table #tt(id int,a varchar(10),b varchar(10),c varchar(10),d varchar(10))
    insert #tt values(1,'a','b','c','d')
    insert #t values(2,'e','f','g','h')
    insert #t values(3,'i','j','k','l')
    insert #t values(4,'m','n','o','p')
    insert #tt(id,a,b,c,d)
    select id,a,b,c,d from(
    select a.id,a.a,b.b,c.c,d.d from #t a
    join #t b
    on a.id=b.id
    join #t c
    on a.id=c.id
    join #t d
    on a.id=d.id
    ) a order by idselect * from #tt
    select * from #tdrop table #tt
    drop table #t