-1

我有 2 个查询,带有参数。我可以让他们单独报告,但是我想要一份报告中的两个表格。问题是,使用参数的子报表似乎有问题......我的 2 个查询是:

SELECT        A.Store_Number, A.GC_Sold, B.Total_Cars

FROM            (SELECT        Store_Number, COUNT_BIG(Quantity_Sold) AS GC_Sold

FROM            Invoice_Detail_Tb

WHERE        (Invoice_Date BETWEEN CONVERT(DATETIME, @startdate, 102) AND CONVERT(DATETIME, @enddate, 102)) AND (JLI_Category_Code = 'gc') AND (Invoice_Detail_Code LIKE 'jlgc%') AND (Invoice_Detail_Type = 'Item')

GROUP BY Store_Number) AS A INNER JOIN

(SELECT        Store_Number, SUM(Vehicle_Count) AS Total_Cars

FROM            Daily_Sales_Tb

WHERE        (Operations_Day BETWEEN CONVERT(DATETIME, @startdate, 102) AND CONVERT(DATETIME, @enddate, 102))

GROUP BY Store_Number) AS B ON A.Store_Number = B.Store_Number

此输出为我提供了日期范围的数据,如下所示:

Store    gc sold      total cars
1        5             8
2        6             9
3        7             10

我的第二个查询是:

SELECT        A.Store_Number, A.GC_Sold, B.Total_Cars

FROM            (SELECT        Store_Number, COUNT_BIG(Quantity_Sold) AS GC_Sold

FROM            Invoice_Detail_Tb

WHERE        (Invoice_Date = CONVERT(DATETIME, @enddate, 102)) AND (JLI_Category_Code = 'gc') AND (Invoice_Detail_Code LIKE 'jlgc%') AND (Invoice_Detail_Type = 'Item')

GROUP BY Store_Number) AS A INNER JOIN

(SELECT        Store_Number, SUM(Vehicle_Count) AS Total_Cars

FROM            Daily_Sales_Tb

WHERE        (Operations_Day = CONVERT(DATETIME, @enddate, 102))

GROUP BY Store_Number) AS B ON A.Store_Number = B.Store_Number

此输出仅返回 enddate 的数据。并且看起来与上表相同。

用户在 Windows 窗体上选择开始日期和结束日期并按下“开始”。然后将参数传递给报告查看器......有什么想法吗?

4

2 回答 2

0

如果这是一个 SQL Server Reporting Services 报表,那么您可以添加多个数据集。在您的情况下,第一个将使用第一个查询,第二个数据集将使用第二个查询,两个数据集使用相同的共享数据源(=> 数据库连接)。

然后您可以将两个表添加到报表中 - 一个引用第一个数据集作为其数据源,另一个引用第二个数据集。

同样可以为本地报告建模。

于 2012-04-24T12:05:12.327 回答
0

您需要使用第二个查询创建另一个表适配器。设置下一个表格适配器后,您需要将表格添加到报表查看器。添加表格后,将字段从新表格适配器拖到表格中。完成此操作后,转到您的报表查看器控件,为您的新表分配数据集的绑定源,然后

于 2012-04-25T15:56:41.613 回答