|
The database table StockInOutDtl has 100,000 records. It took me only 1 second to execute the following statement in the stored procedure:
insert into @tmpStock
SELECT B.ArtID, B.ArtDesc, B.Units, -B.Qty as Qty, 0, A.ST
From StockInOut A Left Outer Join StockInOutDtl B
On A.SheetID = B.SheetID
Inner Join RefArtList C On B.ArtID = C.ArtID
Where A.IssueDate> = @ RenewDate
And B.ArtID=@ArtID
But there is no "Inner Join RefArtList C On B.ArtID = C.ArtID" line, that is, the following statement takes 9 seconds:
insert into @tmpStock
SELECT B.ArtID, B.ArtDesc, B.Units, -B.Qty as Qty, 0, A.ST
From StockInOut A Left Outer Join StockInOutDtl B
On A.SheetID = B.SheetID
Where A.IssueDate> = @ RenewDate
And B.ArtID=@ArtID |
|