anorthcote
Programmer
I have the following stored procedure
I run it in query analyzer using
this will return all records and works ok. If I substitute a value for any of the parameters the procedure will filter by the appropriate value. This, again, works fine for all but @Contractor.
If I put a value in for @Contractor the procedure goes from running in 1 second to over a minute. I have found that if I take out the ROWCOUNT statement it runs quickly again.
Why is the ROWCOUNT adding so much processing time to the procedure and only for @Contractor?
Code:
CREATE PROCEDURE Test
@LocationID int,
@StatusID int,
@Area int,
@Contractor int,
@EnteredBy Varchar(20)
AS
BEGIN
SET ROWCOUNT 30
SELECT dbo.Calls.LogID
FROM dbo.Contractor INNER JOIN
dbo.ContractorOrder ON dbo.Contractor.ID = dbo.ContractorOrder.ContractorID RIGHT OUTER JOIN
dbo.CallStatus INNER JOIN
dbo.Calls ON dbo.CallStatus.ID = dbo.Calls.StatusID LEFT OUTER JOIN
dbo.Location ON dbo.Calls.LocationID = dbo.Location.ID LEFT OUTER JOIN
dbo.Area ON dbo.Location.AreaID = dbo.Area.ID ON dbo.ContractorOrder.OrderID = dbo.Calls.OrderID
where (@LocationID = 0 OR LocationID = @LocationID) AND
(@StatusID = 0 OR StatusID = @StatusID) AND
(@area = 0 OR cast(substring(dbo.Area.Name,6,2) as int) = @area) AND
(@Contractor = 0 OR ContractorOrder.ContractorID = @Contractor) AND
(@EnteredBy = '' OR Calls.EnteredBy = @EnteredBy)
order by LogID Desc
end
GO
I run it in query analyzer using
Code:
exec test 0,0,0,0,''
this will return all records and works ok. If I substitute a value for any of the parameters the procedure will filter by the appropriate value. This, again, works fine for all but @Contractor.
If I put a value in for @Contractor the procedure goes from running in 1 second to over a minute. I have found that if I take out the ROWCOUNT statement it runs quickly again.
Why is the ROWCOUNT adding so much processing time to the procedure and only for @Contractor?