select * from syscolumns a, sysobjects b where a.object_id=b.object_id and b.name='dingdan' and a.name not in('编号','datafilename')
报错,是因为我是sqlserver2005,没有obejct_id,而是id,所以改一下是:
select * from syscolumns a, sysobjects b where a.id=b.id and b.name='dingdan' and a.name not in('编号','datafilename')
这样就对了~~~
最后是这样:
declare @c_sql varchar(8000) set @c_sql='' select @c_sql=@c_sql+ a.name+',' from syscolumns a, sysobjects b where a.id=b.id and b.name='dingdan' and a.name not in('编号','datafilename') set @c_sql=left(@c_sql,len(@c_sql)-1) select @c_sql set @c_sql='select '+@c_sql+' from dingdan' EXEC(@c_sql)