行列转换的问题

create table tb(材料费用 int,人工费用 int,机械费用 int,其他费用 int)
insert into tb select 150,260,330,400
go

declare @sql varchar(8000)
set @sql=''
select@sql=@sql+' union all select '''+name+''' as 费用类型,'+name+' as 数目 fromtb ' from syscolumns where id=object_id('tb') order by colid
set @sql=stuff(@sql,1,11,'')
exec(@sql)
drop table tb

原文地址:https://www.cnblogs.com/smallfa/p/1663482.html