我正在尝试创建一个联合两个数据集的报告。它需要(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];
有人知道或看到我可能会丢失什么吗?任何帮助,将不胜感激!