我正在嘗試創建一個報告,指出UNION的兩個數據集。它需要(1)特定客戶在一個日期範圍內的一堆訂單,並將其與(標題和)聯合(2)運輸方法,後面跟着放置訂單和訂單之間的時間間隔的平均值發送。Visual Studio報告中的聚合報告不顯示
下面的屏幕截圖顯示,在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];
是否有人知道或看到什麼我可能會丟失? 任何幫助,將不勝感激!
注意:我不確定爲什麼屏幕截圖分裂了這句話,但它似乎並不想讓我修復它。 –