I have a stored proc that runs in 1:13, but when I copy the SQL and define the parameters in SQL Server Management Studio, it runs in less than 1 second. Is there anything that would cause the SP to NOT use the existing indexes SP code is below:
SELECT
DISTINCT People.People_GUID,People_Desc =isnull
(LastName,'') + ', ' + ISNULL(FirstName,'') + ' ' + cast(PersonNumber as varchar(10))FROM
People,cpccase cc
,PeoplePersonType PPT
where
People.Customer_GUID = @Customer_GUIDand
CC.Customer_GUID = @Customer_GUIDand
PPT.Customer_GUID = @Customer_GUIDand
People.People_GUID = CC.People_GUIDand
CC.Active = 1and
People.People_GUID = PPT.People_GUIDand
PPT.PersonType_GUID = @PersonType_GUIDand
(@Query is null or isnull(LastName,'') + ', ' + ISNULL(FirstName,'') + ' ' + cast(PersonNumber as varchar(10)) like @Query + '%')order
by 2
Thanks!
Mike