--如:declare @col varchar(8000) Select @col=isnull(@col,'')+','+name from syscolumns where id=object_id('test') and name<>'A' order by colid set @col=stuff(@col,1,1,'') Exec('Select '+@col+' from test ')
--这样试一下! Declare @t Varchar(1000) Set @t=' Select ' Select @t=@t+Name+',' From SysColumns Where id=Object_id('Test') and Name <>'A' Select @t=Stuff(@t,len(@t),1,'')+' From Test' Exec (@t)
select * into # from test Alter Table # drop column a select * from # drop table #
Select @col=isnull(@col,'')+','+name
from syscolumns where id=object_id('test') and name<>'A' order by colid
set @col=stuff(@col,1,1,'')
Exec('Select '+@col+' from test ')
Declare @t Varchar(1000)
Set @t=' Select '
Select @t=@t+Name+',' From SysColumns Where id=Object_id('Test') and Name <>'A'
Select @t=Stuff(@t,len(@t),1,'')+' From Test'
Exec (@t)
Alter Table # drop column a
select * from #
drop table #