0

我正在嘗試創建一個報告,指出UNION的兩個數據集。它需要(1)特定客戶在一個日期範圍內的一堆訂單,並將其與(標題和)聯合(2)運輸方法,後面跟着放置訂單和訂單之間的時間間隔的平均值發送。Visual Studio報告中的聚合報告不顯示

下面的屏幕截圖顯示,在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]; 

是否有人知道或看到什麼我可能會丟失? 任何幫助,將不勝感激!

+0

注意:我不確定爲什麼屏幕截圖分裂了這句話,但它似乎並不想讓我修復它。 –

回答

0

這不是空白,它可能不在您所期望的列中 - 我可以在屏幕截圖中看到值「24」。

+0

截圖來自SQL Server。我試圖證明我在SQL Server中得到了我期望的結果,但是當我運行24值爲空的報告時 - 即使查詢和參數完全相同。 –

0

我想出了我的錯誤是什麼。 有關值24的列和標題和值列的大小設置不同。在SQL Server中,它似乎並不在意,但是在Visual Studio中,它看到了大小的差異,實際上從顯示中刪除了整列。

當我將平均值列調整爲VARCHAR(48)(這是上面列的大小)後,它再次正確顯示。