create table #t ( 年 int, 其它字段 varchar(10) ) insert into #t select 2011,'aaa' union all select 2011,'bbb'insert into #t select 2012,其它字段 from #t where 年=2011select * from #t
按1楼的写法,如果楼主嫌10个字段写起来麻烦的话,可以参考一下这种做法select * into #tt from #t where 年=2011 update #t set 年=2102 inset into #t select * from #tt
select 2012 as 第一个字段名,* from table where 第一个字段名=2011
TABLE1 ---原表 TABLE2 ---对象表INSERT INTO TABLE2 SELECT 除年字段其他字段, '2012' AS 年 FROM TABLE1 WHERE 年 = '2011'两个表的字段对应上就OK
declare @t table (col1 int,col2 int,col3 int,col4 int,col5 int,col6 int,col7 int,col8 int,col9 int,col10 int) insert into @t select 2011,1,1,1,1,1,1,1,1,1 union all select 2011,1,1,1,1,1,1,1,1,1 union all select 2010,1,1,1,1,1,1,1,1,1insert into @t ( col1 , col2 , col3 , col4 , col5 , col6 , col7 , col8 , col9 , col10 ) select '2012', col2 , col3 , col4 , col5 , col6 , col7 , col8 , col9 , col10 from @t where col1=2011
(
年 int,
其它字段 varchar(10)
) insert into #t
select 2011,'aaa' union all
select 2011,'bbb'insert into #t select 2012,其它字段 from #t where 年=2011select * from #t
update #t set 年=2102
inset into #t select * from #tt
select 2012 as 第一个字段名,* from table where 第一个字段名=2011
TABLE2 ---对象表INSERT INTO TABLE2 SELECT 除年字段其他字段, '2012' AS 年 FROM TABLE1 WHERE 年 = '2011'两个表的字段对应上就OK
declare @t table
(col1 int,col2 int,col3 int,col4 int,col5 int,col6 int,col7 int,col8 int,col9 int,col10 int)
insert into @t
select 2011,1,1,1,1,1,1,1,1,1 union all
select 2011,1,1,1,1,1,1,1,1,1 union all
select 2010,1,1,1,1,1,1,1,1,1insert into @t
( col1 ,
col2 ,
col3 ,
col4 ,
col5 ,
col6 ,
col7 ,
col8 ,
col9 ,
col10
)
select '2012',
col2 ,
col3 ,
col4 ,
col5 ,
col6 ,
col7 ,
col8 ,
col9 ,
col10 from @t where col1=2011
select * from @t
/*
col1 col2 col3 col4 col5 col6 col7 col8 col9 col10
----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
2011 1 1 1 1 1 1 1 1 1
2011 1 1 1 1 1 1 1 1 1
2010 1 1 1 1 1 1 1 1 1
2012 1 1 1 1 1 1 1 1 1
2012 1 1 1 1 1 1 1 1 1
*/
SELECT '2012' 年, Col2,Col3,……,Col10 FROM Tabel_Name WHERE Col1 = '2011'
我用的是很古老的绿屏系统,只能用一句sql不能这样多句一起的。