我正在尝试从 C# 应用程序在 SQL Server 2008 上执行存储过程。这需要很多时间,我的应用程序“没有响应”。我的存储过程:
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 条记录。我还能尝试什么?我做错了什么?