declare @fdname sysname
select @fdname=quotename(name) from syscolumns
where id=object-id('你要查询的表')
   and colid=3   --列的序号
if @@rowcount >0
exec('select '+@fdname+' from 你要查询的表')

解决方案 »

  1.   

    老大一出手,就知道有没有,学习了~~~where id=object-id('你要查询的表')
    where id=object_id('你要查询的表')
      

  2.   

    UP zjcxc(邹建) 
    declare @fdname sysname
    select @fdname=quotename(name) from syscolumns
    where id=object_id('msgtable20060401')
       and colid=3   --列的序号
    if @@rowcount >0
    exec('select '+@fdname+' from msgtable20060401')