你只要修改一下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
)')
exec('select '+@sField+',count(*) as CountValue from TC_tnCLT where (cast(MONTH as int) BETWEEN 200205 AND 200305)
group by @sField
order by CountValue
)')
from TC_tnCLT
where (cast(MONTH as int) BETWEEN 200205 AND 200305)
group by '+ @sField
+' order by CountValue')用动态SQL
exec('select '+@sField+',count(*) as CountValue from TC_tnCLT where (cast(MONTH as int) BETWEEN 200205 AND 200305)
group by '+@sField+'
order by CountValue
)')