我使用存储过程为我的SSRS报告提供数据集。在我的存储过程中是一个名为@ReportType的参数。我使用这个,因为我有两个使用相同数据子集的报告,但是它们根据@ReportType返回不同的列,而在一个报告类型中我汇总了数据。
例如,我的存储过程的结束如下:
---Income
IF @Rpt_Type = 'Income'
BEGIN
SELECT
EXPENSE_TYPE
, ACCOUNT_NAME
, CURRENCY
, SETTLEMENT_DATE
, ISSUE
, ISSUE_DESCRIPTION
, SETTLEMENT_AMOUNT
, TRANSACTION_STATUS
, TRANSACTION_CATEGORY
, TRANSACTION_SUBCATEGORY
, TRANSACTION_DESCRIPTION
FROM #RESULT_SET
WHERE TRANSACTION_CATEGORY IN ('IN','IF') OR (TRANSACTION_CATEGORY IN ('CD','CW') AND TRANSACTION_SUBCATEGORY IN ('INT','SLI','RDS','INS','INC'))
ORDER BY expense_type,settlement_date,issue_description
END
---Expenses
IF @Rpt_Type = 'Expenses'
BEGIN
BEGIN
SELECT
ACCOUNT_NAME AS [Portfolio_Number]
, TRANSACTION_SUBCATEGORY AS [Cash_flow_type]
, TRANSACTION_DESCRIPTION AS [Cash_Flow_Description]
, COUNT(ACCOUNT_NAME) AS [Number Of Transactions]
, @ReportEndDate AS [EndDate]
FROM #RESULT_SET
WHERE TRANSACTION_SUBCATEGORY IN ('CCD','CCW','FSB','FSS','FFB','FFS','FSO','FSC','FFO','FFC')
AND INQ_BASIS_NUM = '1'
GROUP BY ACCOUNT_NAME,TRANSACTION_SUBCATEGORY,TRANSACTION_DESCRIPTION,TRANSACTION_CATEGORY
ORDER BY ACCOUNT_NAME,TRANSACTION_SUBCATEGORY,TRANSACTION_DESCRIPTION,TRANSACTION_CATEGORY
END
我的问题是如何让SSRS返回每种报告类型的不同列?有没有一种方法可以创建数据集,我可以在将列返回到SSRS之前提供参数供我使用?我是否必须在SSRS中创建两个数据集以满足所需的不同列?
答案 0 :(得分:0)
只要为每个@Rpt_Type返回相同的列名,这将起作用。对于@Rpt_Type'收入',返回@Rpt_Type'费用'数据的NULL值,反之亦然。否则,报告将期望未从数据集获取的列和数据集将失败:
---Income
IF @Rpt_Type = 'Income'
BEGIN
SELECT
EXPENSE_TYPE
, ACCOUNT_NAME
, CURRENCY
, SETTLEMENT_DATE
, ISSUE
, ISSUE_DESCRIPTION
, SETTLEMENT_AMOUNT
, TRANSACTION_STATUS
, TRANSACTION_CATEGORY
, TRANSACTION_SUBCATEGORY
, TRANSACTION_DESCRIPTION
, NULL Portfolio_Number
, NULL Cash_flow_type
, NULL Cash_Flow_Description
, NULL [Number Of Transactions]
, NULL EndDate
FROM #RESULT_SET
WHERE TRANSACTION_CATEGORY IN ('IN','IF') OR (TRANSACTION_CATEGORY IN ('CD','CW') AND TRANSACTION_SUBCATEGORY IN ('INT','SLI','RDS','INS','INC'))
ORDER BY expense_type,settlement_date,issue_description
END
---Expenses
IF @Rpt_Type = 'Expenses'
BEGIN
BEGIN
SELECT NULL EXPENSE_TYPE
, NULL ACCOUNT_NAME
, NULL CURRENCY
, NULL SETTLEMENT_DATE
, NULL ISSUE
, NULL ISSUE_DESCRIPTION
, NULL SETTLEMENT_AMOUNT
, NULL TRANSACTION_STATUS
, NULL TRANSACTION_CATEGORY
, NULL TRANSACTION_SUBCATEGORY
, NULL TRANSACTION_DESCRIPTION
, ACCOUNT_NAME AS [Portfolio_Number]
, TRANSACTION_SUBCATEGORY AS [Cash_flow_type]
, TRANSACTION_DESCRIPTION AS [Cash_Flow_Description]
, COUNT(ACCOUNT_NAME) AS [Number Of Transactions]
, @ReportEndDate AS [EndDate]
FROM #RESULT_SET
WHERE TRANSACTION_SUBCATEGORY IN ('CCD','CCW','FSB','FSS','FFB','FFS','FSO','FSC','FFO','FFC')
AND INQ_BASIS_NUM = '1'
GROUP BY ACCOUNT_NAME,TRANSACTION_SUBCATEGORY,TRANSACTION_DESCRIPTION,TRANSACTION_CATEGORY
ORDER BY ACCOUNT_NAME,TRANSACTION_SUBCATEGORY,TRANSACTION_DESCRIPTION,TRANSACTION_CATEGORY
END