你只要修改一下SELECT 语句就可以了。改成:
exec('select '+@sField+',count(*) as CountValue from TC_tnCLT where (cast(MONTH as int) BETWEEN 200205 AND 200305)  
        group by @sField
        order by CountValue
)')

解决方案 »

  1.   

    exec('select ' + @sField + ',count(*) as CountValue
            from TC_tnCLT 
            where (cast(MONTH as int) BETWEEN 200205 AND 200305)  
            group by   '+ @sField
     +'        order by CountValue')用动态SQL
      

  2.   

    哦,犯了个错误.应该是
    exec('select '+@sField+',count(*) as CountValue from TC_tnCLT where (cast(MONTH as int) BETWEEN 200205 AND 200305)  
            group by '+@sField+'
            order by CountValue
    )')
      

  3.   

    表名,字段等做变量必须用动态SQL
      

  4.   

    上面有位大哥提到动态SQL,这是一个什么概念,可否指点一二?