DECLARE @NoClient Int SET @NoClient=3831141 SELECT TOP 1 Invoice.AddUser,Invoice.NoFormat FROM Invoice (NOLOCK) WHERE Invoice.NoClient=@NoClient AND (Invoice.NoStatus=5 OR Invoice.NoStatus=6 OR Invoice.NoStatus=7 OR Invoice.NoStatus=10) ORDER BY Invoice.AddDate DESCThis provides an adequate execution plan with simply one item at 100% exactly to the index I have created.
DECLARE @NoClient Int DECLARE @NoStatus Int DECLARE @NoStatus2 Int DECLARE @NoStatus3 Int DECLARE @NoStatus4 Int SET @NoClient=3831141 SET @NoStatus=5 SET @NoStatus2=6 SET @NoStatus3=7 SET @NoStatus4=10 SELECT TOP 1 Invoice.AddUser,Invoice.NoFormat FROM Invoice (NOLOCK) WHERE Invoice.NoClient=@NoClient AND (Invoice.NoStatus=@NoStatus OR Invoice.NoStatus=@NoStatus2 OR Invoice.NoStatus=@NoStatus3 OR Invoice.NoStatus=@NoStatus4) ORDER BY Invoice.AddDate DESCThe execution goes completely weird simply because I passed a parameter.