简体   繁体   English

如果数据具有层次结构,如何设计 SSRS 报告和 SQL 服务器表?

[英]How to design SSRS Report and SQL Server Table if data has a hierarchy?

I have to design table and the SSRS report that contains data in below format.我必须设计表格和包含以下格式数据的 SSRS 报告。

Please click on below URL to download excel sheet here请点击下面的 URL 下载 excel 表在这里

Once you downloaded the file, see the tab that contains RAW Data.下载文件后,请查看包含 RAW 数据的选项卡。 It lists all the figures on row with rollover summation (ie states "AF", "GN" and "OZ") and months are separated by columns它列出了行上的所有数字以及翻转总和(即状态“AF”、“GN”和“OZ”),月份由列分隔

The issue here is that the month should be generated dynamically based on current month.这里的问题是应该根据当前月份动态生成月份。 Hence right now the report shows data for September Month, but I am not sure how to store values for future month in database and how to show all months data in report.因此,现在报告显示 9 月份的数据,但我不确定如何在数据库中存储未来月份的值以及如何在报告中显示所有月份的数据。

Should I create table with all future months or should I mentions "Months" column dynamically?我应该创建包含所有未来月份的表格还是应该动态提及“月份”列?

Please note that USA states and rollover formula remains constant and I am able to write a query to generate states value.请注意,美国州和翻转公式保持不变,我可以编写查询来生成州值。

The database structure I have thought of (& the reporting structure) is visible in Tab "Sample Report"我想到的数据库结构(和报告结构)在“示例报告”选项卡中可见

I am just trying what you have tried to do.我只是在尝试您尝试做的事情。 i think you need to create column grouping for month.我认为您需要为月份创建列分组。 just try with below dataset for your ref.只需尝试使用以下数据集作为参考。

CREATE TABLE #TEMP_RAW_DATA
(
    N_id NUMERIC(18,0) IDENTITY(1,1),
    VC_Country VARCHAR(30),
    VC_States VARCHAR(50),
    D_Date DATE,
    I_Values INT
)

INSERT INTO #TEMP_RAW_DATA
(
    VC_Country,VC_States,D_Date,I_Values
)
SELECT 'USA','Alabama','09-01-2019',57 UNION ALL
SELECT 'USA','Alabama','10-01-2019',47 UNION ALL
SELECT 'USA','Alabama','11-01-2019',69 UNION ALL
SELECT 'USA','Alabama','12-01-2019',1 UNION ALL
SELECT 'USA','Alabama','01-01-2020',42 UNION ALL
SELECT 'USA','Hawaii','09-01-2019',80 UNION ALL
SELECT 'USA','Hawaii','10-01-2019',55 UNION ALL
SELECT 'USA','Hawaii','11-01-2019',19 UNION ALL
SELECT 'USA','Hawaii','12-01-2019',73 UNION ALL
SELECT 'USA','Hawaii','01-01-2020',76 UNION ALL
SELECT 'USA','Massachusetts','09-01-2019',20 UNION ALL
SELECT 'USA','Massachusetts','10-01-2019',74 UNION ALL
SELECT 'USA','Massachusetts','11-01-2019',30 UNION ALL
SELECT 'USA','Massachusetts','12-01-2019',36 UNION ALL
SELECT 'USA','Massachusetts','01-01-2020',53 UNION ALL
SELECT 'USA','Pennsylvania','09-01-2019',53 UNION ALL
SELECT 'USA','Pennsylvania','10-01-2019',17 UNION ALL
SELECT 'USA','Pennsylvania','11-01-2019',1 UNION ALL
SELECT 'USA','Pennsylvania','12-01-2019',13 UNION ALL
SELECT 'USA','Pennsylvania','01-01-2020',42 UNION ALL
SELECT 'USA','Virginia','09-01-2019',26 UNION ALL
SELECT 'USA','Virginia','10-01-2019',24 UNION ALL
SELECT 'USA','Virginia','11-01-2019',29 UNION ALL
SELECT 'USA','Virginia','12-01-2019',79 UNION ALL
SELECT 'USA','Virginia','01-01-2020',73

SELECT VC_Country,VC_States,DATENAME(MONTH,D_Date) VC_Month,
CASE 
    WHEN PATINDEX('[a-f]%',VC_States)>0 THEN 'A-F'
    WHEN PATINDEX('[g-n]%',VC_States)>0 THEN 'G-N'
    WHEN PATINDEX('[o-z]%',VC_States)>0 THEN 'O-Z'
END VC_Group,
SUM(I_Values) I_Values
FROM #TEMP_RAW_DATA
GROUP BY VC_Country,VC_States,
CASE 
    WHEN PATINDEX('[a-f]%',VC_States)>0 THEN 'A-F'
    WHEN PATINDEX('[g-n]%',VC_States)>0 THEN 'G-N'
    WHEN PATINDEX('[o-z]%',VC_States)>0 THEN 'O-Z'
END,DATENAME(MONTH,D_Date)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM