I have a query, and even using SQL Sentry, I can't eliminate the index scan.
This is the query:
SELECT TOP 30 codCliente FROM (
SELECT t1.CodCliente, codcampo, valor, t1.chavealeat
FROM tblCliente AS t1 WITH(NOLOCK)
INNER JOIN tblClienteDetalhe AS t2 WITH(NOLOCK)
ON t1.codcliente = t2.codcliente
AND CodCampo IN(-1, 4)
WHERE codStatus IN (0)
AND t1.ChavePeriodo < GETDATE()
AND t1.CodStatusLigacao = 0
AND EXISTS
(
SELECT codcliente FROM tblclientedetalhe WITH(NOLOCK)
WHERE codcampo = 3 AND valor = '2'
AND codcliente = t1.codcliente
)
AND EXISTS
(
SELECT codcliente FROM tblclientedetalhe WITH(NOLOCK)
WHERE codcampo = 6
AND CONVERT(DATETIME, Valor) BETWEEN '2015-08-01' AND '2015-08-31'
AND DATEDIFF(DAY, Valor, GETDATE()) > 15
AND codcliente = t1.codcliente
)
AND NOT EXISTS
(
SELECT 0 FROM tblPesquisa WITH(NOLOCK)
WHERE tblPesquisa.CodCliente = t1.CodCliente
)
AND EXISTS
(
SELECT codcliente FROM tblclientedetalhe WITH(NOLOCK)
WHERE codcampo = 4 and valor = '202' and codcliente = t1.codcliente
)
) AS Cliente
Pivot (MAX(Valor) FOR codCampo in ([4])) AS PivotTable
WHERE (((([4] = '202'))))
ORDER BY chavealeat;
This is the index I made:
create index IX_CHAVEALEAT_CODCLIENTE
on tblcliente (chavealeat,codcliente)
include (chaveperiodo,codstatus,codstatusligacao)
And, this is the analysis:
Why is the plan showing index scan? I'm covering all columns. I used option(recompile) to update the plan.
Is this index wrong? The output is only codcliente.
I have 10-30 queries running at the time, and theres no wait_info problems.

