如何将一个DataTable到ReportingService样基质? [英] How to transform a datatable to a ReportingService-like matrix?
问题描述
问:
我有我从一个数据库,它看起来像这样检索数据:
I have data that I retrieve from a database, which looks like this:
现在,我需要将其转换到下面的格式,以便能够得出一个饼图。
在ReportingService,还有就是矩阵的控制来实现这一点,但我有什么可以用它来实现普通C#一样,为了使它对一个饼图的形象?
Now I need to transform it to the below format, in order to be able to draw a piechart.
In ReportingService, there is the Matrix control to achieve this, but what can I use to achieve the same in ordinary C#, in order to render it to a PieChart image ?
请注意该建筑物的数目以及该利用类型是可变的,而不是事先已知的
Note that the number of buildings as well as the usage-types is variable and not known ahead of time.
编辑:
解决了由于马格努斯和谷歌:
Solved thanks to Magnus and Google:
SELECT * FROM
(
SELECT
STE_Designation AS RPT_Site
,BDG_Designation AS RPT_Building
,UG_Code AS RPT_Usage_Code
,UG_Caption AS RPT_Usage
,SUM(MP_RMArea_Area) AS RPT_Area
FROM V_RPT_RoomDetail
WHERE (RM_MDT_ID = 1)
GROUP BY
STE_Designation
,BDG_Designation
,UG_Code
,UG_Caption
--ORDER BY STE_Designation, BDG_Designation, UG_Code, UG_Caption
) AS SourceTable
PIVOT
(
SUM(RPT_Area)
FOR RPT_Building IN ([Building1], [Building2], [BuildingN])
) AS PivotTable
ORDER BY RPT_Site, RPT_Usage_Code
当支点列需要在code。通过生成的选择是不同的。
Where the pivot columns need to be generated in code by a select distinct.
推荐答案
您应该看一看在SQL PIVOT运算 http://msdn.microsoft.com/en-us/library/ms177410.aspx
You should have a look at the SQL Pivot operator http://msdn.microsoft.com/en-us/library/ms177410.aspx
这篇关于如何将一个DataTable到ReportingService样基质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!