0

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

下面的屏幕截图显示,在 SQL Server 中,查询运行良好。但是,当我在 Visual Studio 2008 中运行这个完全相同的查询来为此创建报告时,平均周转时间的实际值在此处输入图像描述是空的。

据我所知,在 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];

有人知道或看到我可能会丢失什么吗?任何帮助,将不胜感激!

4

2 回答 2

0

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

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

于 2012-10-11T15:53:53.113 回答
0

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

于 2012-10-10T15:58:50.497 回答