Visual Studio报表中的聚合未显示

时间:2012-10-10 15:54:21

标签: tsql visual-studio-2008 reporting-services aggregate-functions

我正在尝试创建一个UNIONs两个数据集的报告。它需要(1)日期范围内的特定客户的一堆订单,并且UNIONs与(标题和)(2)运输方法遵循下订单和订单之间的时间间隔的平均值发送。

下面的屏幕截图显示,在SQL Server中,查询工作正常。但是,当我在Visual Studio 2008中运行此完全相同的查询来为此创建报表时,平均周转时间enter image description here的实际值为空。

据我所知,在SQL Server中,查询可以完美地用于我给它的任何参数。我只是无法弄清楚为什么在报告中平均周转时间总是空白。

我正在运行的查询是:

DECLARE @turnaroundInfo TABLE
(
    [Owner Reference] VARCHAR(48),
    [Project] VARCHAR(48),
    [Carrier Type] VARCHAR(48),
    [Created Date] DATETIME,
    [Shipped Date] DATETIME,
    [Turnaround Time (hours)] INT
)
INSERT INTO @turnaroundInfo
SELECT orders.ownerReference AS [Owner Reference], p.name AS [Project], types.name AS [Carrier Type], orders.createdSysDateTime AS [Created Date], shipments.shippedDate AS [Shipped Date],  DATEDIFF(HOUR,             orders.createdSysDateTime, shipments.shippedDate) AS [Turnaround Time (hours)]
FROM datex_footprint.Orders orders
    INNER JOIN datex_footprint.Projects p ON orders.projectId = p.id
    INNER JOIN datex_footprint.CarrierServiceTypes types ON orders.preferredCarrierServiceTypeId = types.id
    INNER JOIN datex_footprint.OrderLines lines ON orders.id = lines.orderId
    INNER JOIN datex_footprint.Shipments shipments ON lines.shipmentId = shipments.id
WHERE p.name IN (@project)  AND types.name IN(@carrier)

-- Get only the type and date-ranged turnaround info we want
DECLARE @orders TABLE
(
    [Owner Reference] VARCHAR(48),
    [Project] VARCHAR(48),
    [Carrier Type] VARCHAR(48),
    [Created Date] DATETIME,
    [Shipped Date] DATETIME,
    [Turnaround Time (hours)] INT
)
INSERT INTO @orders
SELECT  *
FROM @turnaroundInfo
WHERE [Turnaround Time (hours)] >= 0 AND [Created Date] BETWEEN @startDate AND @endDate
ORDER BY [Turnaround Time (hours)], [Carrier Type] ;


-- UNION the relevant turnaround infor with headers
SELECT * FROM @orders o /*  All the orders in the date range for this project and the selected carrier(s) */
UNION ALL
SELECT 'Carrier' AS [Carrier Type], 'Avg Turnaround Time' AS [Average Turnaround], NULL AS Column3, NULL AS Column4, NULL AS Colummn5, NULL AS Column6
UNION ALL
SELECT o.[Carrier Type], CAST(AVG(o.[Turnaround Time (hours)]) AS NVARCHAR(24)) AS [Average Turnaround], NULL AS Column3, NULL AS Column4, NULL AS Colummn5, NULL AS Column6
FROM @orders o
GROUP BY o.[Carrier Type];

有人知道或看到我可能遗失的内容吗? 任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:0)

它不是空白,它可能不在您预期的列中 - 我可以在屏幕截图中看到值“24”。

答案 1 :(得分:0)

我弄清楚我的错误是什么。 关于值24和标题和24值列的列的大小不同。在SQL Server中,它似乎并不关心,但在Visual Studio中它看到了大小差异,实际上从显示中删除了整个列。

在我将平均值列调整为VARCHAR(48)后,它就是上面列的大小,再次正确显示。