日期:2014-05-18 浏览次数:20656 次
go create table t1( C1 INT, C2 INT, C3 INT ) go create table t2( C1 INT, C2 INT, C3 INT, D1 INT ) declare @str varchar(2000) set @str='' select @str=@str+','+name from syscolumns where id=object_id('t1') and exists(select 1 from(select name from syscolumns where id=object_id('t2'))a where a.name=name) set @str='insert t2 select '+right(@str,len(@str)-1)+' from t1' print @str --insert t2 select C1,C2,C3 from t1 --你只需动态执行 exec(@str)