excel交叉表转换_新手怎么做报表

excel交叉表转换_新手怎么做报表–列转行小实例 –创建测试表 if object_id(N'test', N'U') is not null drop table test go with UnP

一个简单的交叉报表_列转行

--列转行小实例
--创建测试表
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分

交叉前

excel交叉表转换_新手怎么做报表

交叉后

excel交叉表转换_新手怎么做报表

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/8406.html

(0)
上一篇 2023-02-28
下一篇 2023-02-28

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注