0
When making a SELECT COUNT(*)
in the 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)
By selecting the tax bills 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)
That is, of the total 3498
I have 2697
within the time limit, thus the 801
remaining of that account would be the late ones. However, when making the query to verify this, the value is incorrect: 1293
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 am looking for a way to check these records and compare them to know what is returning to more in the latter SELECT
. I found the controls INTERSECT
and EXCEPT
but they did not help me in the solution.
Marcelo, from what I was able to extract from your conversation with @Ciganomorrisonmendez, only one of the dates should be used in the comparison, by the name of their fields, I can infer that the
dataPrevista
will always be completed and will be used ifdataAgendamento
is void, or bydataAgendamento
takes precedence over thedataPrevista
.– Tobias Mesquita
Exactly, @Tobymosque.
– Marcelo de Andrade
Curiosity, and if you did this: AND NOT (Date Receipt <= Date Expected or Date Received <= Date Gendering)
– cantoni
Nothing, @Cantoni... Adding the line, the count returns
103
, the value is not that.– Marcelo de Andrade
@Marcelodeandrade, without access to data is difficult to help in cases like this. But I suggest you do some checks, for example, the 801 records were not found via SQL, but doing (3498-2697=801). There may be records in your database that do not meet the SQL of the out-of-date you are trying to do. Maybe only the 103 found by my logic and the Gypsy meet. The rest must have some problem in the data that do not make them be returned. It’s time to scan some records and check what happens to the data. Export everything to Excel and filter there.
– cantoni
@Cantoni just what I’m trying to do now. I want a valid way to compare the values returned between these two queries.
– Marcelo de Andrade