When I make a SELECT COUNT(*)
in view vwNotaFiscal
I get the total of lines: 3498
SELECT COUNT(*) FROM dbo.vwNotaFiscal
WHERE
tbEmbarques_emissao BETWEEN CONVERT(DATE,'01/05/2016',103) AND CONVERT(DATE,'31/05/2016',103)
AND (dataRecebimento is not null and recebimento_embarque is not null)
When I select the invoices that were delivered on time, I make the SELECT
below and return me 2697
SELECT COUNT(*) FROM dbo.vwNotaFiscal
WHERE
tbEmbarques_emissao BETWEEN CONVERT(DATE,'01/05/2016',103) AND CONVERT(DATE,'31/05/2016',103)
AND (dataRecebimento is not null and recebimento_embarque is not null)
AND (datarecebimento <= dataprevista OR datarecebimento <= dataAgendamento)
In other words, of the total 3498
I have 2697
on time, so the remaining%% of this account would be overdue. But when you query to verify this, the value is incorrect: 801
SELECT COUNT(*) FROM dbo.vwNotaFiscal
WHERE
tbEmbarques_emissao BETWEEN CONVERT(DATE,'01/05/2016',103) AND CONVERT(DATE,'31/05/2016',103)
AND (dataRecebimento is not null and recebimento_embarque is not null)
AND (datarecebimento > dataprevista OR datarecebimento > dataAgendamento)
I'm looking for a way to check these records and compare them to know what's coming back on the last 1293
. I found the commands SELECT
and INTERSECT
but they did not help me in the solution.