create procedure zhuan @i int
as
declare @col1 nvarchar(200), @col2 nvarchar(200),@col3 nvarchar(200)
declare @sql varchar(200)
set@col1=(select name from syscolumns where id=(select id
from sysobjects where name='table1' ) and colid=5+1)
set @col2=(select name from syscolumns where id=(select id
from sysobjects where name='table1)and colid=@i+2)
set @col3=(select name from syscolumns where id=(select id
from sysobjects where name='table1')and colid=@i+3)
set @sql= 'selecta ,b ,c ,d,'+@col1+','+@col2+','+@col3+' into linshi
from table1'
exec(@sql)
我不知道是不是这么理解你的意思,你是准备把表格拆成n个小的表格?每个表个都有a,b,c,d四列+三列?我是这么理解的,如果是这样的话,看看这个存储过程吧,我写得不好,作拉一个叫做linshi的表格,作为中转区,先把数据放在这里,然后把数据导入到新的表格里面同时删掉linshi,每次用的时候都要删除一次linsihi表格。这么在参数里面设置表格名字的参数我就不知道了,如果知道了话,就不用建立那个linshi的表格拉,去WC喽
|