SELECT Client.Numero FROM Client INNER JOIN Invoice ON Client.Numero=Invoice.NoClient WHERE Client.NoEntity=@NoEntity AND Client.Fic_Date<@Fic_Date AND Invoice.Amount=@Amount AND Client.Loss_Code=@Loss_Code AND Client.CType=@CTypeThis would take 2 seconds to return 45 records. But, the following would be instant:
SELECT Client.Numero FROM Client INNER JOIN Invoice ON Client.Numero=Invoice.NoClient WHERE Client.NoEntity=@NoEntity AND Client.Fic_Date<@Fic_Date AND Invoice.Amount=1000 AND Client.Loss_Code=@Loss_Code AND Client.CType=@CTypeI tried to change a lot of things in there. The only way I can have my query to be optimized is by avoiding the parameter on the foreign table. But, I really need to have everything parameterized. What can I do?