62,046
社区成员
发帖
与我相关
我的任务
分享
--带条件
insert into 表
select a,b+1,c from 表 where 字段1=
insert into 表
select a,b+1,c from 表
[code=SQL]--改了下 试试
declare @strinsert varchar(1000)
declare @strSelect varchar(1000)
select @strinsert='b'
select @strSelect='b+1'
select @strinsert=isnull(@strinsert+',','')+name,@strSelect=isnull(@strSelect+',','')+name
from syscolumns
where [name]<>'a' and [name]<>'b' and id=object_id('tb')
print('insert into tb('+@strinsert+') select '+@strSelect+' from tb ')
exec('insert into tb('+@strinsert+') select '+@strSelect+' from tb ')
[/code]--试试
declare @strinsert varchar(1000)
declare @strSelect varchar(1000)
select @strinsert='b'
declare @strSelect='b+1'
select @strinsert=isnull(@strinsert',','')+name,@strSelect=isnull(@strSelect',','')+name
from syscolumns
where [name]<>'a' and [name]<>'b' and id=object_id('tb')
print('insert into tb('+@strinsert+') select '+@strSelect+' from tb ')
exec('insert into tb('+@strinsert+') select '+@strSelect+' from tb ')