SQL竖变横

declare @sql varchar(8000);


select distinct Repp
into #repp
from v_datayearall;

select a_code,i_code,repp,a_name,i_name+case when t_indct.m_code is not null then '('+s_name+')' else '' end as i_name
into #tempType
from t_INDCT,t_area,#repp,t_Scale
where t_INDCT.i_code in ('1','2','3','4','5','6','7')
and t_area.a_code in ('420321102000','420321102200','420321102201','420321102202','420321102203','420321102204')
and repp in ('2005')
and t_INDCT.m_code = t_Scale.m_code
and scale = 0;

declare @exp money;

set @exp=10;
select #tempType.*,ISNULL(convert(nvarchar,convert(decimal(30,3),case when Data is not null and scale is not null then Data*power(@exp,scale) else Data end)),text_data) data
--into #tempMain
from v_datayearall ,#tempType
where v_datayearall.i_code =* #tempType.i_code
and v_datayearall.a_code =* #tempType.a_code
and v_datayearall.repp =* #tempType.repp;

select distinct a_name as a_name,a_code
into #temptin
from #tempMain
order by a_code;

set @sql = 'select i_name as 指标';
select @sql = @sql + ',max(case a_name
when '''+a_name+''' then data end) ['+a_name+']'
from #temptin;set @sql = @sql+' from #tempMain group by i_code,i_name order by i_code';

exec(@sql);

drop table #repp;
drop table #tempType;
drop table #tempMain;
drop table #temptin;
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值