declare @sql varchar(8000)
set @sql = 'select 期数,商品编码 '
select @sql = @sql + ' , (case 客户名称 when ''' + 客户名称 + ''' then isnull(count(客户名称),0) else 0 end) [' + 客户名称 + ']'
from (select distinct 客户名称 from xs_销售订单统计 group by 客户名称) as a
set @sql = @sql + ' from xs_销售订单统计 where 期数=''03 ''and 商品编码=''ABCDEF100'' group by 期数,商品编码,客户名称'
exec(@sql)