我試圖從C#應用程序執行SQL Server 2008上的存儲過程。這需要很多時間,我的應用程序「沒有響應」。我的存儲過程:需要很長時間的SQL查詢
ALTER PROCEDURE [dbo].[PROC066]
@date_1 date,
@date_2 date
AS
SELECT
RTRIM(tt1.[Org]) as 'Org',
RTRIM(tt1.[CustomerHQ]) as 'Customer',
RTRIM(tt1.[Customer]) as 'ShipTo',
RTRIM(tt1.[Date]) as 'Date',
RTRIM(tt2.Clean) as 'Clean',
RTRIM(tt1.[PO number]) as 'PONumber',
RTRIM(tt1.[GCAS]) as 'GCAS',
'Description' = (SELECT DISTINCT [Description] FROM tDeploymentDB WHERE tDeploymentDB.[Item Code] = tt1.[GCAS]),
RTRIM(tt1.NQTY) as 'NQTY',
RTRIM(tt1.[Dummy]) as 'Dummy',
RTRIM(tt1.[MOQ]) as 'MOQ',
RTRIM(tt1.[Inactive]) as 'Inactive',
RTRIM(tt1.[Allocation]) as 'Allocation',
RTRIM(tt1.[MultiSector]) as 'MultiSector',
RTRIM(tt2.Pallet_Checked) as 'FullPallets',
RTRIM(tt2.FullTruck_Checked) as 'Full_Truck',
FROM tCleanOrderTracking_prod as tt1, tCleanOrderTracking_HDR_prod as tt2
WHERE
SUBSTRING(RTRIM(tt1.[PO number]), 6, LEN(RTRIM(tt1.[PO number])) - 5) =
RTRIM(tt2.CustomerOrderNumber) AND
tt1.[Date] = @date_1 AND tt1.[Date] <= @date_2
ORDER BY Org, [PO Number]
如果我試圖在SQL Server Management Studio上執行此過程 - 它需要5-7秒。但通過C#我無法執行此查詢。我試圖在查詢中刪除此行
tt1.[Date] = @date_1 AND tt1.[Date] <= @date_2
之後,它..我的應用程序需要5秒,執行工作正常。我也試圖改寫這一行
tt1.[Date] BETWEEN @date_1 AND @date_2
沒有結果!我在查詢tCleanOrderTracking_prod中的主表有大約40500條記錄。我可以嘗試其他什麼?我做錯了什麼?
約翰米切爾我真的很感激你。你給的文章是非常有用的。 – mbigun 2012-07-24 12:01:14