--测试环境
Create table #T(Type varchar(10),[Count] int)
insert into #T select 'BA',10
union all select 'CA',18
union all select 'CR',15
union all select 'HA',20
--动态SQL
declare @s varchar(2000)
set @s='Select '
select @s=@s+'['+Type+']=sum(case when type='''+Type+''' then [count] end),'
from #T
group by Type
set @s=left(@s,len(@s)-1)
set @s=@s+' from #T '
exec (@s)
--结果
BA CA CR HA
----------- ----------- ----------- -----------
10 18 15 20
--删除测试环境
Drop table #T