大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说excel交叉表转换_新手怎么做报表,希望您对编程的造诣更进一步.
--列转行小实例 --创建测试表 if object_id(N"test", N"U") is not null drop table test go with UnPivotTable as ( select 1 as UserNO, "33" as A, "44" AS B, "55" as C union all select 2 as UserNO, "23" as A, "34" AS B, "56" as C ) select * into test from UnPivotTable go --创建存储过程 if exists(select name from sysobjects where name = "usp_GetUnPivotInfo") drop proc usp_GetUnPivotInfo go create proc usp_GetUnPivotInfo as declare @SQL nvarchar(4000) SELECT @SQL=isnull(@SQL+",","")+quotename(Name) FROM syscolumns WHERE ID=object_id("test") and [name] not in ("UserNO") ORDER BY Colid SET @SQL="select UserNO,[Attr],[value] from (select * from test) a unpivot ([value] for [Attr] in("+@SQL+"))b" exec(@SQL); go exec usp_GetUnPivotInfo ;
代码100分
交叉前
交叉后
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/8406.html