日期:2014-05-18 浏览次数:20976 次
--用动态 declare @sql varchar(max) declare @mmm varchar(100) set @mmm = 'atype' set @sql = 'select count(*),'+@mmm+' from tb group by '+@mmm exec(@sql)
------解决方案--------------------
--动态sql exec ('select count(*),'+@mmm+' from T_TermDescofLD group by '+@mmm)
------解决方案--------------------
while @@FETCH_STATUS=0
begin
insert #Temp(countNum,ruler)
exec ('select count(*),'+@mmm+' from T_TermDescofLD group by '+@mmm)
FETCH next from cur_colName INTO @mmm
end