我试图从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