0

ストアド プロシージャは次のとおりです。

CREATE PROCEDURE [dbo].[spManagedRouteSheetList]
@dStartDate DateTime,
@dEndDate DateTime
AS
BEGIN 
SELECT IT.TriggerParentID,IT.ProductID, IT.[Weight],IT.[DateTime],IT.ProductType,IT.InOutType,IT.TriggerParentType FROM ITransaction IT 
    WHERE IT.InOutType=101 and IT.LotID in (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate

    --YarnCategory 
    SELECT YarnCategoryID,Name,Code FROM YarnCategory WHERE YarnCategoryID IN (SELECT Distinct ProductID FROm ITransaction IT WHERE IT.InOutType=101 and IT.LotID in (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate) 

    --RouteSheet 
    SELECT RouteSheetID,RoutesheetNo, ReqYarnQty, [date],RSState,Shift,Subfactory,(SELECT Name FROM Location WHERE LocationID=Subfactory) 
    FROM Routesheet where RoutesheetID IN (SELECT distinct IT.TriggerParentID FROM ITransaction IT WHERE IT.InOutType=101 and IT.LotID in (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate)

    --RSInQCDetail
    SELECT RouteSheetID,Qty,YarnFormat,ManagedLotID FROM RSInQCDetail WHERE RouteSheetID IN     (SELECT distinct IT.TriggerParentID FROM ITransaction IT WHERE IT.InOutType=101 and IT.LotID in (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate)


    --RouteSheet History
    SELECT RouteSheetID,YarnQtyInLBS,[Event] from RouteSheetHistoryEnhance WHERE EVENt IN (14) 
    AND RouteSheetID IN (SELECT distinct IT.TriggerParentID FROM ITransaction IT WHERE IT.InOutType=101 and IT.LotID in 
    (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate)

END

実行手順:

EXECUTE dbo.[spManagedRouteSheetList] '21 May 2012 08:00:00','22 May 2012 08:00:00'.. 

2 ミスかかりますが、次のクエリを実行すると 1 ~ 3 秒しかかかりません

DECLARE @dStartDate as datetime
        ,@dEndDate as datetime

        SET @dStartDate='21 May 2012 08:00:00'
        SET @dEndDate='22 May 2012 08:00:00'


SELECT IT.TriggerParentID,IT.ProductID, IT.[Weight],IT.[DateTime],IT.ProductType,IT.InOutType,IT.TriggerParentType FROM ITransaction IT 
    WHERE IT.InOutType=101 and IT.LotID in (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate

    --YarnCategory 
    SELECT YarnCategoryID,Name,Code FROM YarnCategory WHERE YarnCategoryID IN (SELECT Distinct ProductID FROm ITransaction IT WHERE IT.InOutType=101 and IT.LotID in (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate) 

    --RouteSheet 
    SELECT RouteSheetID,RoutesheetNo, ReqYarnQty, [date],RSState,Shift,Subfactory,(SELECT Name FROM Location WHERE LocationID=Subfactory) 
    FROM Routesheet where RoutesheetID IN (SELECT distinct IT.TriggerParentID FROM ITransaction IT WHERE IT.InOutType=101 and IT.LotID in (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate)

    --RSInQCDetail
    SELECT RouteSheetID,Qty,YarnFormat,ManagedLotID FROM RSInQCDetail WHERE RouteSheetID IN     (SELECT distinct IT.TriggerParentID FROM ITransaction IT WHERE IT.InOutType=101 and IT.LotID in (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate)


    --RouteSheet History
    SELECT RouteSheetID,YarnQtyInLBS,[Event] from RouteSheetHistoryEnhance WHERE EVENt IN (14) 
    AND RouteSheetID IN (SELECT distinct IT.TriggerParentID FROM ITransaction IT WHERE IT.InOutType=101 and IT.LotID in ``
    (select ManagedLotID from RSInQCDetail where YarnFormat <>4 and ManagedLotID>0) 
    AND IT.[DateTime]>=@dStartDate AND IT.[DateTime]<@dEndDate)

だから..ストアドプロシージャの問題は何ですか?

4

1 に答える 1

0

これがSQLServerの場合...

これは必ずしも完璧な解決策ではありませんが、見た違いを取り除くことができるかもしれません。

WITH RECOMPILEストアドプロシージャの定義に追加してみてください。

CREATE PROCEDURE [dbo].[spManagedRouteSheetList]
    @dStartDate DateTime,
    @dEndDate DateTime
WITH RECOMPILE
AS ...
于 2012-05-23T13:00:52.407 に答える